
com.Ostermiller.util.ExcelCSV.bte Maven / Gradle / Ivy
<%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=topcontent%>
Utilities for reading and writing CSV (comma separated value) text files in the same format as Microsoft Excel. CSV as supported by these classes uses double quotes as the escape for a literal quote as specified by RFC4180. Libraries for other CSV formats are available.
<%/bte.tpl%>
<%bte.tpl name=content%>
Example
// Create the printer
ExcelCSVPrinter ecsvp = new ExcelCSVPrinter(
System.out
);
// Write to the printer
ecsvp.writeln(
new String[]{
"hello","world"
}
);
Writing Excel CSV files: ExcelCSVPrinter
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 some applications other than Excel can understand use the
standard CSV format. Both CSVPrinter and ExcelCSVPrinter
implement the CSVPrint interface.
Example
// 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("-----");
}
Reading Excel CSV files: ExcelCSVParser
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. Excel CSV has become a defacto standard of its own. It is now specified by RFC4180.
To read standard CSV files that some 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.
<%/bte.tpl%>
<%bte.tpl name=linkExcelCSV%>Excel CSV
<%/bte.tpl%>
<%/bte.doc%>