Sidebar

How can I create a CSV file with headers when appending

+1 vote
583 views
asked Aug 23, 2016 by brandon-w-8204 (33,170 points)
I need to create a CSV file that has a header and append individual records to it. Is this possible.

2 Answers

0 votes
 
Best answer
QIE version 3.0.44 will now handle the header row on a file append and only put one header in. Just check the Append to the file option and if the destination is recieving a CSV with Headers QIE will automatically handle the header and not duplicate it.
answered Aug 29, 2017 by brandon-w-8204 (33,170 points)
edited Aug 29, 2017 by brandon-w-8204
+1 vote

The only way to accomplish this is to use a scheduled script on the channel to make sure the file exists with the header.

Here is the script to remove any header rows from the message before writing it to the file.

var rowContent = message.getNode('*[1]');
message = qie.createCSVMessage();
message.setNode('/', rowContent);
 
Here is a sample scheduled script to create the file with headers.
 
qie.moveFile('c:\\temp\\csvHeaderTest.csv', 'c:\\temp\\csvHeaderTest' + qie.formatDate('yyyyMMddhhmmss') + '.csv', false);
qie.writeFile('c:\\temp\\csvHeaderTest.csv', 'Header1,Header2,Header3,Header4,Header5\n', false);
answered Aug 23, 2016 by brandon-w-8204 (33,170 points)
...