输出到Excel,如何定义不同的列
我正在将数据从数据库输出到 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;
I am outputting data from my DB to Excel (has to be .xls format), but how do I tell Excel to put the data in to a new cell or to start a new line?
/** 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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试 \t 和 \n,就像
\t 代表新列,\n 代表新行
Try \t and \n,just like
\t for new column,\n for new row