Dynamic data import / export

datenbank

simply more productive
Up to 10,000 records can be processed with the freeware version!
Welcome, Guest
Username: Password: Remember me
Welcome to the FlowHeater support forum.

Questions about using FlowHeater are answered here.

TOPIC: How to add 1 line header in write side

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

  • Derus
  • Derus's Avatar
  • Offline
  • New Member
  • Posts: 3
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
The administrator has disabled public write access.

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

  • FlowHeater-Team
  • FlowHeater-Team's Avatar
  • Offline
  • Administrator
  • Posts: 240
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:
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.
The administrator has disabled public write access.

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

  • Derus
  • Derus's Avatar
  • Offline
  • New Member
  • Posts: 3
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.
The administrator has disabled public write access.
Moderators: FlowHeater-Team
Time to create page: 0.074 seconds