gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:52:18 25 4
gpt4 key购买 nike

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

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?

最佳答案

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);

关于php - 在 php 中将数组的数组导出到 Excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10424847/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com