CSV bug?

S

SER

Hiroshi, are you there?

I've got a CVS export from Excel that the csv module is barfing on, and
I'm wondering if there's something I should be doing differently.

In particular, the CSV looks something like this:

row 1, field 1, field 2\r\n
row 2, "some\n
text", field 2\r\n

In particular, rows are delimited by \r\n, but there is only an \n in
the quoted text; it is on this line that the parser appears to be
failing with:

/usr/lib/ruby/1.8/csv.rb:627:in `get_row': CSV::IllegalFormatError
(CSV::IllegalFormatError)

This is with:

# $Id: csv.rb,v 1.4.2.3 2004/05/07 08:48:23 matz Exp $

csv.rb claims to be compatible with CSV that Excel outputs; otherwise,
I'd just blame it on shoddy Microsoft products. :)

--- SER
 
N

NAKAMURA, Hiroshi

Hi,
Hiroshi, are you there?
I've got a CVS export from Excel that the csv module is barfing on, and
I'm wondering if there's something I should be doing differently.

In particular, the CSV looks something like this:

row 1, field 1, field 2\r\n
row 2, "some\n
text", field 2\r\n

CSV module (of mine) just does not expect the space just after field
delimiter(,) and before quote marker(").

0% ruby -rcsv -e 'CSV::Reader.parse(%Q("a","b")) { |row| p row }'
["a", "b"]
0% ruby -rcsv -e 'CSV::Reader.parse(%Q("a", "b")) { |row| p row }'
/usr/local/lib/ruby/1.9/csv.rb:557:in `get_row': CSV::IllegalFormatError
(CSV::IllegalFormatError)
from /usr/local/lib/ruby/1.9/csv.rb:506:in `each'
from /usr/local/lib/ruby/1.9/csv.rb:484:in `parse'
from -e:1

Does Excel generates such a line? Hmm. It must be supported then, even
though it could be a option. Do you expect 'a, "b"' is parsed as
'a,"b"', not an error, right? What do you think about 'a,junk"b"' and
'a,\t\r\n"b"'?

Regards,
// NaHi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,002
Messages
2,570,261
Members
46,858
Latest member
FlorrieTuf

Latest Threads

Top