fossteam / jquery-csv

Automatically exported from code.google.com/p/jquery-csv
MIT License
0 stars 0 forks source link

CSV file created with Excel for Mac fails #44

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I tried importing the Excel file attached with the following code:

reader.onload = function(e){
  var csv = e.target.result;
  var csvArr = $.csv.toArrays(csv);
}

resulting in 'Error: CSVDataError: Illegal Data [Row:1][Col:1]'.

I noticed that most scripts use a regex like 'csv.split(/\r\n|\n/);', which 
isn't working for this file. But the regex 'csv.split(/\r/g);' is. Don't know 
if that is in any way related to the error above, but just in case... 

Original issue reported on code.google.com by dennishu...@me.com on 31 Aug 2014 at 9:06

Attachments:

GoogleCodeExporter commented 8 years ago
Because Excel for mac uses CR (carriage return) as the default line line ending 
for formatting. A convention that even Mac quit using when they transitioned 
from OS9 to OSX.

I don't know if that's the cause of your problem but the code available in the 
repository properly handles old mac style line endings.

I'll be dropping a new release soon that should include the fix. I'll try it 
with your sample to see if it that's the issue.

Original comment by evanpla...@gmail.com on 15 Dec 2014 at 5:12

GoogleCodeExporter commented 8 years ago
I noticed indeed that it's just a difference between Excel for Mac and Excel 
for Windows; when you save files in Excel for Mac you can choose a specific 
format that is compatible, but it's not the default option. The default option, 
even after the latest updates, uses different line endings then Excel for 
Windows does. So it's not just old Mac's, it's also present on OS X Yosemity 
with the latest Office for Mac release. 

If I can be of any assistance, I would be glad to help out and/or test it for 
you. Thanks so much for looking into it!

Original comment by dennishu...@me.com on 15 Dec 2014 at 10:10

GoogleCodeExporter commented 8 years ago
Thanks for chiming in. Sorry if I wasn't clear. What I meant was...

Even on the most recent versions of Excel for Mac, the default for line endings 
is CR. Despite CR being obsolete since the transition from OS9 to OSX. OSX -- 
as a Unix based system -- uses LF as the default line ending for everything.

I'm not sure if the Microsoft devs are just ignorant about OSX conventions or 
if they wrote it that way intentionally as a tongue-in-cheek FU to Apple. 
Either way, it causes a lot of problems for people who are blissfully ignorant 
of the aftermath caused by the OS line ending wars.

If only MS Office had a public bug tracker. If only...

Either way, the source available in the repository (ie not the latest release) 
should contain a fix that properly handles CSV source with CR line endings.

Original comment by evanpla...@gmail.com on 15 Dec 2014 at 10:19