Single " in line results in different reading to excel/open office
Brought to you by:
aruckerjones,
sconway
I've got a couple of files that open ok in Excel and open office, reading each line in the attached csv files into a new row and cell.
In example1.csv opencsv reads only the first 2 of the 5 lines. In example2.csv it reads all the lines, but combines lines 3, 4 & 5.
Here's the code I'm using to do this:
public void testExample2() throws IOException, URISyntaxException
{
final File file = new File(this.getClass().getResource("/example2.csv").toURI().getPath());
final CSVReader reader = new CSVReader(new FileReader(file));
final List<String[]> all = reader.readAll();
int row = 1;
for (String[] strings : all)
{
for (int i = 0; i < strings.length; i++)
{
int col = 1;
System.out.println("[" + row + "][" + col + "]: " + strings[i]);
++col;
}
++row;
}
reader.close();
}
The outputs are:
example1.csv:
example2.csv:
Screenshots to show how the files load in excel.
If you need any other info just shout!
We faced the similar issue while parsing one of the csv files having double quote (") as a part of value -
for example - ABC 26" DE as shown below -
6/16/2016,6/16/2016,XYX,ABC 26" DE,0,PQR,1.00,187
We were using the "parseLine" method of CSVParser class (package au.com.bytecode.opencsv. CSVParser). We did a small modification in this method and it worked. Below is the code snippet for the same.
1) inQuotes = !inQuotes; --> placed below after if loop
2) inQuotes=true;
Let's know if this works for you.
for (int i = 0; i < nextLine.length(); i++) {
Last edit: Tushar Shinde 2016-06-21
I am looking at creating a RFC-4180 compliant reader for Bug #127 and I believe this will fix this issue as well. If anything I will use the two examples you provided as additional test data.
I am still facing this issue with CSVReader. Are there any plans to fix this?
Yes - it is still in the works. Just slow going with family and holidays.
On Tue, Dec 6, 2016 at 1:52 PM, Aditya adityashiva@users.sf.net wrote:
--
Scott Conway
scott.conway@gmail.com
http://www.conwayfamily.name
Related
Bugs:
#126Fixed with the RFC4180Parser in the 3.9 release.