FlowHeater Logo

FlowHeater Support Forum

simply more productive

Download the freeware version (10 Mb)

Up to 100,000 records can be processed with the freeware version!

Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: How to add 1 line header in write side

How to add 1 line header in write side 6 years 3 months ago #2142

I convert an xls file to txt and I must add 1 line in output txt file to complete process. I can't found example in help file or forum. could you help me?
BR/Gilbert

Please Log in or Create an account to join the conversation.

Re:How to add 1 line header in write side 6 years 3 months ago #2143

Hi Gilbert,

I guess you want to write an additional custom header instead of filed column names?

This is possible but a bit tricky. In a further version I plan to make it easier, this will provide custom header and footer information.

The solution)
You need the .NET Script Heater and the script below.
bool bFirstLine = true;

public object DoWork()
{
  if (bFirstLine == true)
  {
    // only write additional header line for the first time
    bFirstLine = false;

    // Get the Textfile adapter on the WRITE side
    TextFileAdapter adapter = (TextFileAdapter)AdapterWrite;
    
    // get the filename
    string filename = adapter.Filename;
    if (File.Exists(filename))
      File.Delete(filename);

    string header = String.Empty;
    // write all input parameters to a separate header line
    for (int i = 0; i < InValues.Length; i++)
    {
      string sTemp = (string)InValues[i].GetString();
      if (sTemp == null)
        sTemp = String.Empty;

      if (header.Length > 0)
        header += "\r\n"; // Newline

      header += sTemp;
    }    

    // Create the text file and write the custom header data
    File.WriteAllText(filename, header);
  }

  return false; // just for Filter Heater, false = no filtering
}
The script writes for all input parameters you added a separate custom header line into the export file. I´ve made a little example; please have a look to the attachment. The Filter Heater in the example is just necessary for execution the script.

So that this works you have to use the option "Append to file" for the TextFile Adapter on the WRITE side.

Note: The additional headers are not writes in Test mode! The TextFile Adapter preview does not display this custom header lines. You have to execute the definition without the test mode option.


Hope this helps.

Attachment additional_header_lines.zip not found

Attachments:

Please Log in or Create an account to join the conversation.

Best wishes
Robert Stark

Did this answer your question? We would be grateful if you provide a brief comment as feedback. It may also help others who may have encountered a similar problem.

Re:How to add 1 line header in write side 6 years 3 months ago #2144

Thanks a lot, I will try this solution who's more elegant than the one I've found!
I want use file2 = copy (file header+ file result) in batch mode.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.088 seconds