1

Cakephp2.0を使用しています。毎日の基本に関するレポートをExcel形式で生成する必要があります。そこで、CSVファイルを生成する関数を作成しました。LinuxマシンでOpenOfficeにファイルをダウンロードすると正常に動作しますが、Windows Microsoftで同じファイルを開こうとすると、セルはありませんが、データは正しく表示されます。これで私は自分のコーディングをリストしました

    $model.= "-".date('d M,Y');
    header ("Expires: Mon, ".date('d M,Y')." GMT");
    header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
    header ("Cache-Control: no-cache, must-revalidate");
    header ("Pragma: no-cache");
    header ("Content-type: application/vnd.ms-excel");
    header ("Content-Disposition: attachment; filename=\"$model.xls" );
    header ("Content-Description: Generated Report" );

誰もが感謝を助けます

4

2 に答える 2

3

ここで何か間違ったことをしているのではないかと思います。ヘッダーを確認してください。質問でcsvについて言及し、Excelヘッダーを作成しています。それは混乱するかもしれませんMS Excel

header ("Content-type: application/vnd.ms-excel");
header ("Content-Disposition: attachment; filename=\"$model.xls" );
header ("Content-Description: Generated Report" );

私はこの種のヘッダー形式を使用しています。これは、WindowsやOpenOfficeで完全に機能します。これを試してみてください。

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-type: octet/stream");
header("Content-Type: application/force-download");
header("Content-Type: application/download");
header("Content-disposition: attachment; filename=" . basename($filename.".csv"));
header("refresh: 0; url= ".$redirect_url);
于 2012-08-27T11:44:31.913 に答える
1

データ列はコンマではなくセミコロンで区切る必要があるため、ExcelCSVファイルにはSSVファイルという名前を付ける必要があります。また、データは引用符で囲む必要があり、内側の引用符は二重引用符としてエスケープする必要があります。例:1;"Some ""string"" with escapes"

于 2012-08-27T11:12:37.853 に答える