TDIing out loud, ok SDIing as well

Ramblings on the paradigm-shift that is TDI.

Thursday, June 16, 2011

Adding custom headers lines to CSV output

I've gotten this questions a few times recently: how to put custom content at the top of a CSV file.

One solution would be to code the After Close Hook for the File System Connector, creating a new file that combined the headers and the CSV content. However, there is an easier solution (thanks again to Jens 'Beautiful Mind' Thomassen):

Add the following script to the After Initialize Hook of the Connector:
// At this point, the Parser is also initialized,
// so you can grab the it uses.
stream = thisConnector.connector.getParser().getWriter()
// Then add your custom content
stream.writeln("this is the first line")
stream.writeln("this is the second line")

And that's all there is to it. When the Connector does its first write operation, the field names will be written after the custom lines.

No comments: