- Posts: 3
How to add 1 line header in write side
- Derus
- Topic Author
- Offline
- User
Less
More
13 years 4 months ago #2142
by Derus
How to add 1 line header in write side - Post(2142) was created by Derus
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
BR/Gilbert
Please Log in or Create an account to join the conversation.
- FlowHeater-Team
- Offline
- Admin
13 years 4 months ago #2143
by FlowHeater-Team
Best wishes
Robert Stark
Replied by FlowHeater-Team on topic Re:How to add 1 line header in write side - Post(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.
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.
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.
Code:
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
}
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
Best wishes
Robert Stark
Attachments:
Please Log in or Create an account to join the conversation.
- Derus
- Topic Author
- Offline
- User
Less
More
- Posts: 3
13 years 4 months ago #2144
by Derus
Replied by Derus on topic Re:How to add 1 line header in write side - Post(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.
I want use file2 = copy (file header+ file result) in batch mode.
Please Log in or Create an account to join the conversation.
Time to create page: 0.262 seconds