代码如下:
//横向单元格标识 $cellName = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R'); $newName = time().rand(100,300).'.csv'; $source_file = FILENAME.'template/import/'.$file_name; $destination = $error_path.$newName; $startLine = 3; //从第三行开始写入数据 $objPHPExcel = \PHPExcel_IOFactory::load($source_file); // print_r($objPHPExcel);die; $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $cols = count($testValue[0]); $len = count($testValue); // print_r($cols);die; for ($i=0; $i < $len; $i++) { for ($j = 0; $j < $cols; $j++) { $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$j] . ($i+$startLine), $testValue[$i][$j], \PHPExcel_Cell_DataType::TYPE_STRING); } } $objPHPExcel->setActiveSheetIndex(0); $objWriter->save($destination);
改良版(2018/09/27):
错误提示列即改良列:
之前:
之后: