0

PHP スクリプトから Excel ファイルのさまざまな行にさまざまな配列を書き込みたいと考えています。私はそれを行う方法がたくさんあることを知っています。

Excel ファイルをダウンロードする小さなスクリプトを取得しましたが、コンテンツに挿入する配列をサポートしていません。変更が必要な場合は、助けてください。

ありがとう

    $shop['id']=$column['id'];
    $shop['name']=$column['name'];
    $shop['cat1'] = $cat1;
    $shop['cat2'] = $cat2;
    $shop['cat3'] = $cat3;
    $all_shops[$column['id']] = $shop; 



$filename ="cat.xls";
$contents = "$shop['cat2']";
header('Content-type: application/ms-excel');
header('Content-Disposition: attachment; filename='.$filename);
echo $contents;
4

1 に答える 1

-1

最も簡単な方法は、出力でコンテンツを HTML としてストリーミングすることです。(例:拡張子 .html を .xls に変更すると Excel でスムーズに開きます)

$shop['id']=$column['id'];
$shop['name']=$column['name'];
$shop['cat1'] = $cat1;
$shop['cat2'] = $cat2;
$shop['cat3'] = $cat3;
$all_shops[$column['id']] = $shop; 

$content = "<table>";
foreach($all_shops as $k => $shop){
   $content .= "<tr><td>ID</td><td>{$shop['id']}</td></tr>"; // add other columns
}
$content .= "</table>";

$filename ="cat.xls";
$contents = "$shop['cat2']";
header('Content-type: application/ms-excel');
header('Content-Disposition: attachment; filename='.$filename);
echo $contents;
于 2012-10-19T10:59:25.860 に答える