[PHP]export array to excel (or csv)

有關網頁及相關語法的討論
回覆文章
頭像
tim
文章: 1318
註冊時間: 2008年 11月 26日, 00:49

[PHP]export array to excel (or csv)

文章 tim » 2015年 5月 31日, 13:58

http://stackoverflow.com/questions/1042 ... ell-in-php

代碼: 選擇全部

$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);
多多留言, 整理文章, 把經驗累積下來.....

回覆文章