Skip to content

Commit a29402b

Browse files
committed
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
1 parent 0c2cdca commit a29402b

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

src/site/xdoc/user-guide.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<document>
19+
<properties>
20+
<title>User Guide</title>
21+
<author email="dev@commons.apache.org">Commons Documentation Team</author>
22+
</properties>
23+
<body>
24+
<!-- ================================================== -->
25+
<section name="Parsing an Excel CSV File">
26+
<p>To parse an Excel CSV file, write:</p>
27+
<source>Reader in = new FileReader(&quot;path/to/file.csv&quot;);
28+
Iterable&lt;CSVRecord&gt; records = CSVFormat.EXCEL.parse(in);
29+
for (CSVRecord record : records) {
30+
String lastName = record.get("Last Name");
31+
String firstName = record.get("First Name");
32+
}</source>
33+
</section>
34+
<section name="Handling Byte Order Marks">
35+
<p>
36+
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.
37+
You can use the
38+
<a href="https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/input/BOMInputStream.html">BOMInputStream</a>
39+
class from <a href="https://commons.apache.org/proper/commons-io/">Apache Commons IO</a> for example:
40+
</p>
41+
<source>final URL url = ...;
42+
final Reader reader = new InputStreamReader(new BOMInputStream(url.openStream()), "UTF-8");
43+
final CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader());
44+
try {
45+
for (final CSVRecord record : parser) {
46+
final String string = record.get("SomeColumn");
47+
...
48+
}
49+
} finally {
50+
parser.close();
51+
reader.close();
52+
}</source>
53+
</section>
54+
<!-- ================================================== -->
55+
</body>
56+
</document>

0 commit comments

Comments
 (0)