Roger Barnes wrote:
Hi Stu,
I am wondering if anyone else has had this problem?


I have. :)


When we create a CSV (comma seperated values) text file in our app and firefox passes it to Excel (yes I know, immovable object currently but working on it! OO _is better), all of the data is thrown to column one in a completely boneheaded manner.

Normally, one would expect Excel to start the whole import text file stuff ie how the text should be imported (delimited/fixed) whatever.


If you haven't already, try naming the file from the web browser with a .csv extension
For example, if your application is a cgi, eg 
http://somehost.com/sendsomecsv.php?param1=value1, try adding a csv filename 
after the script name, eg 
http://somehost.com/sendsomecsv.php/export.csv?param1=value1

Also, try experimenting with the content-type header that you return:
Content-type: application/vnd.ms-excel
Content-type: application/csv
Content-type: text/csv

One or both of these approaches has worked for me in different situations, but 
I'm not sure how well it applies for firefox.


This works in Firefox for our application using php4.
Excel doesn't ask you what to do with it because it already knows (and always gets it wrong). Different versions of Excel don't handle this the same so it might need tweaking.

If this doesn't do what you want there are programs to write proper Excel files and you shouldn't have to do any escaping/fugding the data.

header('Content-type: application/octet-stream');
$filename = date("d-M-Y-") . 'file.csv';
header("Content-Disposition: attachment; filename=$filename");
header('Pragma: no-cache');
header('Expires: 0');

If there are any fields that start with 0 (zero) it will drop the leading 0 unless you fool it by adding an equal sign and double quote the value ,=\"$fieldname\",

I have found that it doesn't matter what spreadsheet program you use, they are all braindead when used this way, including 00 and Gnumeric.
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to