setHeader

void csvWriter.setHeader ( String[ ] header )

Description

Set the header row of the csv document. If the document already exists the headers will not be written. Also creates a data record mapping to ease writing to file.

Parameters

  • header Headers of csv file, as a one-dimensional array of strings.

Return Values

Returns void.

Change Log

Version Description
5.0 Available for all editions.
4.5.18a Introduced in alpha version.

If you want to use the data record mapping then the extractor tokens names should be all caps and all spaces should be replaced with underscores.

Examples

Add Headers to CSV File

 // Create CsvWriter with timestamp
 CsvWriter writer = new CsvWriter("output.csv", true);

 // Create Headers Array
 String[] header = {"Brand Name", "Product Title"};

 // Set Headers
 writer.setHeader(header);

 // Write out to file
 writer.flush();

 // Save in session variable for general access
 session.setVariable( "WRITER", writer);