%bte.doc super="item.bte" %> <%bte.tpl name=pageTitle%>Excel Comma Separated Values (CSV)<%/bte.tpl%> <%bte.tpl name=description%>Java libraries to read and write files in Excel Comma Separated Value (CSV) format.<%/bte.tpl%> <%bte.tpl name=keywords%>excel csv java, java excel csv, comma separated values excel java, cvs excel java, microsoft excel csv format java<%/bte.tpl%> <%bte.tpl name=content%>
// Create the printer ExcelCSVPrinter ecsvp = new ExcelCSVPrinter( System.out ); // Write to the printer ecsvp.writeln( new String[]{ "hello","world" } );
This class makes it easy to output Excel CSV. Given values, it will automatically determine if they need to be quoted and escape special characters. Comments can easily be written and correct line beginnings will be added.
To write standard CSV files that most applications other than Excel can understand use the standard CSV format. Both CSVPrinter and ExcelCSVPrinter implement the CSVPrint interface.
[Download /w Source | Version History | Browse Source | Documentation]
// Parse the data String[][] values = ExcelCSVParser.parse( new StringReader( "hello,world\n" + "how,are,you" ) ); // Display the parsed data for (int i=0; i<values.length; i++){ for (int j=0; j<values[i].length; j++){ System.out.println(values[i][j]); } System.out.println("-----"); }
Microsoft's Excel spreadsheet has on option to export to comma separated value format. However it fails to use the standard CSV file format. Excel does not use the backslash as an escape character, but instead escapes quote literals with two quotes. It also does not quote values that have leading or trailing whitespace. This special CSV parser can read Excel format CSV files.
To read standard CSV files that most applications other than Excel can understand use the standard CSV format. Both CSVParser and ExcelCSVParser implement the CSVParse interface.
If the first line of your CSV file is a row of column headings, consider wrapping this parser in a Labeled CSV Parser.
[Download /w Source | Version History | Browse Source | Documentation]