0

I am generating a csv file with php.

It works fine in windows, linux. But in mac (excel) it comes in a messed way.

All data comes in one column and does not get seperated by commas.

I was wondering if there is any way to pass headers for mac excel so it identifies the seperator (comma) by default.

Here are the header that I been using.

header("Content-type: application/vnd.ms-excel");
//header('Content-type: application/ms-excel');
//header("Content-Type: text/x-csv");
header("Content-disposition: csv" . date("Y-m-d") . ".xls");
header("Content-disposition: filename=".$filename.".xls");
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".strlen($csv_output));
header("Pragma: no-cache");
header("Expires: 0");

Thanks Abhi

4

1 回答 1

0

使用时,

header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".xls");
header("Content-disposition: filename=".$filename.".xls");

您正在创建一个 Excel 文件并在其中插入 CSV 数据。您可以尝试将其用作标题:

header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=file.csv");
于 2012-06-27T01:16:35.687 回答