我正在将调查中的一些数据导出为 CSV 以供另一个使用 PHP 的团队使用。我已将第一行数据作为所有标题输出。但我需要一些标题来跨越 2 列是完全可能的。
标题都正确,但我需要在某些标题下添加两个数据单元格。
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=lite-survey-data_'.time().'.csv');
require_once ( dirname(dirname(dirname(dirname(__FILE__)))).'/wp-load.php' );
$content =build_csv_download();
$headings = convert_to_csv($content[0]);
$csv_content = convert_to_csv($content[1]);
$output = fopen('php://output', 'w');
fwrite($output, $headings);
fwrite($output, $csv_content);
有什么想法吗?
最佳答案
标题不可能跨越两列,因为 CSV 是一种基本格式,不允许您表示合并的单元格。但是,如果两列中的第二列没有标题(所以 heading,,nextheading
),那么当您在 Excel 中打开它时,heading
将散布到空单元格中。
关于PHP CSV 列标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8096900/