在php中将数组数组导出到Excel

use*_*513 4 php arrays excel

我在每个子数组的开头有一个数组数组是列的标题,后跟我要填充列的整数.它看起来像这样:

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 ) )
Run Code Online (Sandbox Code Playgroud)

有没有办法分解数组并将其导出到Excel?

Bab*_*aba 19

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);
Run Code Online (Sandbox Code Playgroud)

  • 这就像一个魅力非常感谢你!你刚刚睡了一个晚上我就救了我 (2认同)