| Issue 4: | How do I write a CSV file with a header? | |
| 4 people starred this issue and may be notified of changes. | Back to list |
StringWriter sw = new StringWriter();
CSVWriter csvWriter = new CSVWriterBuilder(sw)
.entryConverter(new MyConverter()).strategy(
new CSVStrategy('\t', '\"', '#', false, true)).build();
//Add the header row
csvWriter.write(new String[] { "col1", "col2", "col3" });
csvWriter.writeAll(editors);
String csvData = sw.toString();
??
Dec 8, 2014
#1
acsta...@gmail.com
Feb 24, 2015
This lib doesn't support headers yet, so you must provide them to your writer like this.
StringWriter sw = new StringWriter();
//Add the header row
sw.write("col1;col2;col3\n");
CSVWriter csvWriter = new CSVWriterBuilder(sw)
.entryConverter(new MyConverter()).strategy(
new CSVStrategy('\t', '\"', '#', false, true)).build();
csvWriter.writeAll(editors);
String csvData = sw.toString();
|