When creating a csv file in PHP and allowing a user to download it for import in Microsoft Excel you might have come accross the problem where it says. This is not a valid file extension and is a SYLK file.
This is nothing you did wrong. If you passed the headers as per below:
header('Content-type: text/csv'); header('Content-Disposition: attachment; filename="report.csv"'); echo '"ID","NAME"'; echo '"5","CHRIS"'; die();
The problem lies in excel identifying a file as SYLK when the first two characters of the file is "ID".
The easy fix is to just change that field to "Id" or "id" or even "iD" like this:
header('Content-type: text/csv'); header('Content-Disposition: attachment; filename="report.csv"'); echo '"Id","NAME"'; echo '"5","CHRIS"'; die();
I see it as a bug in Excel as I can't imagine how much frustration has been caused by this because it doesn't make any sense. Either way let me know if this helped you.
By PHPin24 @ 2010-02-02 10:53:34
|