My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
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
Status:  New
Owner:  ----


 
Reported by joe.osow...@gmail.com, Feb 7, 2013
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
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.
Feb 24, 2015
#3 yuumei...@gmail.com
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();

Powered by Google Project Hosting