What to do if you get a weird error when trying to open a CSV file you just created

I just came across an, erm interesting issue when exporting some data to a CSV file. When I tried to open the file in Excel, I got the rather helpful error message “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 want to open it anyway?

If you click the Yes button, then you get the even more helpful error message “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.

At this point, you go and look to see if there are any jobs going on the cashiers at Tesco!

Turns out that the fix is very simple. If you export an ID field in the data, and includes headers in the .csv file, then the first two characters of your .csv file will be “ID” which Excel decides isn’t on, and so throws up a few misleading error messages to make your life more interesting! Note that this only applies if the first two characters are “ID” as opposed to “id” or “Id” where Excel lets you off.

So, if you need to export the ID field, don’t name it “ID” or Excel will throw a hissy fit!

Be First to Comment

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.