Excel Comma Separated Values (CSV) - com.Ostermiller.util Java Utilities
|
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.
Example// Create the printer ExcelCSVPrinter ecsvp = new ExcelCSVPrinter( System.out ); // Write to the printer ecsvp.writeln( new String[]{ "hello","world" } ); Writing Excel CSV files: ExcelCSVPrinterThis 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: ExcelCSVParserMicrosoft'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. |
OstermillerUtil Java Utilities Copyright (c) 2001-2007 by Stephen Ostermiller and other contributors
The OstermillerUtils library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
License FAQs - Why GPL? How about the LGPL or something else?