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

时间:2012-01-18 11:10:51

标签: 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 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;

1 个答案:

答案 0 :(得分:1)

尝试\ t和\ n,就像

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

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