8

各サブ配列の先頭にある配列の配列は、列のヘッダーであり、その後に列に入力する整数が続きます。次のようになります。

Array ( [0] => Array ( [0] => How was the Food? [1] => 3 [2] => 4 ) [1] => Array ( [0] => How was the first party of the semester? [1] => 2 [2] => 4 [3] => 0 ) )

配列を分割して Excel にエクスポートする方法はありますか?

4

3 に答える 3

27

Excelはcsvファイルを直接開くことができます...試してください

$array = Array (
        0 => Array (
                0 => "How was the Food?",
                1 => 3,
                2 => 4 
        ),
        1 => Array (
                0 => "How was the first party of the semester?",
                1 => 2,
                2 => 4,
                3 => 0 
        ) 
);

header("Content-Disposition: attachment; filename=\"demo.xls\"");
header("Content-Type: application/vnd.ms-excel;");
header("Pragma: no-cache");
header("Expires: 0");
$out = fopen("php://output", 'w');
foreach ($array as $data)
{
    fputcsv($out, $data,"\t");
}
fclose($out);
于 2012-05-03T04:05:46.517 に答える
4

本当に配列を Excel にエクスポートしたい場合は、PHPReportをご覧ください。phpexcel でのエクスポートを簡素化するために、そのクラスを作成しました。xls と xlsx をサポートしています。

于 2012-05-16T19:33:34.073 に答える