示例代码下方。它可能会帮助你.. 当我将行号(1)更改为5时,excel表中的七行为空。(LOCATION:setCellValueByColumnAndRow($ col,1,$ field);)
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setTitle("export")->setDescription("none");
$objPHPExcel->setActiveSheetIndex(0);
$fields = array('ram','one','two');
$col = 0;
foreach ($fields as $field)
{
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, 1, $field);
$col++;
}
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename="Export.csv"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
答案 0 :(得分:1)
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setTitle("export")->setDescription("none");
$objPHPExcel->setActiveSheetIndex(0);
$field = array('ram','one','two');
$col = 0;
foreach ($fields as $field)
{
if(empty($field)){
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, 1, $field);
$col++;
}
}
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename="Export.csv"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
答案 1 :(得分:1)
您正在定义$field
但是预先引用$fields
.... s
会产生很大的不同
$field = array('ram','one','two');
和
foreach ($fields as $field)
尝试使用正确的变量名称
定义数组$fields = array('ram','one','two');