9

The file is created in javascript and downloaded through an a tag. But Excel complains that there is something wrong with the file format.

  1. In what file format will Excel not throw errors?
  2. And can this be generated with javascript?

Apparently Excel wants the BOM at the beginning, but I have no idea how to change that. The file is encoded in Base64.

First error: The file format and extension of 'filename.csv' don't match. The file could be corrupted or unsafe. Unless you trust its source, don't open it. Do you wan to open it anyway?

Second error after Yes: Excel has detected that 'filename.csv' is a SYLK file, but cannot load it. Either the file has errors or it is not a SYLK file format. Click OK to try to open the file in a different format.

2
  • 2
    Does your output file start with 'ID' ? If so then open the csv in a text editor and change it. support.microsoft.com/en-us/kb/215591 for more info.
    – bob dylan
    Jul 23, 2015 at 13:00
  • Thanks, that should only take care of the second error, but it took care of both! If you put that as answer I'll accept it.
    – MrFox
    Jul 24, 2015 at 7:12

2 Answers 2

35

Does your output file start with 'ID' ? If so then open the csv in a text editor and change it. see http://support.microsoft.com/en-us/kb/215591 for more info

EDIT:

That link is now dead - however using the wayback machine it said:

MORE INFORMATION A SYLK file is a text file that begins with "ID" or "ID_xxxx", where xxxx is a text string. The first record of a SYLK file is the ID_Number record. When Excel identifies this text at the beginning of a text file, it interprets the file as being a SYLK file. Excel attempts to convert the file from the SYLK format, but is unable to because there are no valid SYLK codes following the "ID" characters. Because it cannot convert the file, Excel generates the error.

https://support.microsoft.com/en-us/help/170245/prj-files-saved-as-csv-can-t-be-opened-in-microsoft-excel

This is another link which explains it - not sure how long this link will last either so here's a screen capture for future reference also:

alternate link for preservation

1
  • @mjwrazor - Thanks, I've added a new link
    – bob dylan
    Mar 14, 2018 at 17:01
3

Ran into this annoying issue when creating CSV files for customers. If you're the one writing CSV files and open them in Excel, instead of "ID", use "Id".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.