Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 输出到Excel时,如何定义不同的列_Php_Excel_Cells - Fatal编程技术网

Php 输出到Excel时,如何定义不同的列

Php 输出到Excel时,如何定义不同的列,php,excel,cells,Php,Excel,Cells,我正在将数据从数据库输出到Excel(必须是.xls格式),但如何告诉Excel将数据放入新单元格或开始一行 /** Set the headers */ header('Content-type: application/vnd.ms-excel'); header('Content-disposition: attachment;filename=referrals.xls'); /** Output the column headers (We don't need the ID, so

我正在将数据从数据库输出到Excel(必须是.xls格式),但如何告诉Excel将数据放入新单元格或开始一行

/** Set the headers */
header('Content-type: application/vnd.ms-excel');
header('Content-disposition: attachment;filename=referrals.xls');

/** Output the column headers (We don't need the ID, so drop it) */
foreach($referrals[0] as $key => $value) :
    $array_keys[$key] = $key;
endforeach;
unset($array_keys['ID']);
echo join('???', $array_keys).'New row???';

/** Output the data */
foreach($referrals as $referral) : foreach($referral as $key => $value) :
        $referral_array[$key] = $value;
    endforeach;
    unset($referral_array['ID']);
    echo join('???', $referral_array).'New row???';
endforeach;

尝试\t和\n,就像

echo join("\t", $array_keys)."\n";

\t表示新列,\n表示新行

您使用的Excel writer库是什么?您的数据实际上是什么样子的?不使用编写器-直接从数据库中以数组的形式获取数据,然后如上所述输出数据。我不需要任何漂亮的东西,只要一堆数据。