dfoulkes / jcsv

Automatically exported from code.google.com/p/jcsv
0 stars 0 forks source link

How do I write a CSV file with a header? #4

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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();

??

Original issue reported on code.google.com by joe.osow...@gmail.com on 7 Feb 2013 at 5:46

GoogleCodeExporter commented 8 years ago
I would like to know how to do this as well. It's a great CSV utility, but I 
want to also supply headers to CSVs that I write.

Original comment by acsta...@gmail.com on 8 Dec 2014 at 7:58

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
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();

Original comment by yuumei...@gmail.com on 24 Feb 2015 at 2:22