Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate .csv file for Excel without error messages?

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.

like image 581
MrFox Avatar asked Jul 23 '15 12:07

MrFox


1 Answers

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

like image 83
bob dylan Avatar answered Nov 16 '22 03:11

bob dylan