From a29402b41ce260e639d3d5ca11c35418a7f874ff Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Fri, 11 Jul 2014 19:07:31 +0000 Subject: [PATCH] Add new user guide (missed that in the last commit) git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1609772 13f79535-47bb-0310-9956-ffa450edef68 --- src/site/xdoc/user-guide.xml | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/site/xdoc/user-guide.xml diff --git a/src/site/xdoc/user-guide.xml b/src/site/xdoc/user-guide.xml new file mode 100644 index 00000000..40e63dc5 --- /dev/null +++ b/src/site/xdoc/user-guide.xml @@ -0,0 +1,56 @@ + + + + + User Guide + Commons Documentation Team + + + +
+

To parse an Excel CSV file, write:

+ Reader in = new FileReader("path/to/file.csv"); +Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(in); +for (CSVRecord record : records) { + String lastName = record.get("Last Name"); + String firstName = record.get("First Name"); +} +
+
+

+ To handle files that start with a Byte Order Mark (BOM) like some Excel CSV files, you need an extra step to deal with these optional bytes. + You can use the + BOMInputStream + class from Apache Commons IO for example: +

+ final URL url = ...; +final Reader reader = new InputStreamReader(new BOMInputStream(url.openStream()), "UTF-8"); +final CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader()); +try { + for (final CSVRecord record : parser) { + final String string = record.get("SomeColumn"); + ... + } +} finally { + parser.close(); + reader.close(); +} +
+ + +