使用PHPExcel和setCellValue方法设置单元格值

时间:2015-08-06 19:23:04

标签: php phpexcel

我试图在Excel(.xlsx)文件中设置一些值,并使用phpoffice/phpexcel库。这就是我的代码的样子:

$objReader = \PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load($filename);
$objWorksheet = $objPHPExcel->getActiveSheet();

$objPHPExcel->getActiveSheet()->setCellValue('A'.$cRow, $hcpId); // set column A - HCP.ID - value
$objPHPExcel->getActiveSheet()->setCellValue('B'.$cRow, $terrID); // set column B - TERRITORY.ID - value
$objPHPExcel->getActiveSheet()->setCellValue('C'.$cRow, $isMatch); // set column C - isMatch TERR_HCP_XREF - value

echo "HCP.ID A{$cRow} => {$hcpId}, TERRITORY.ID B{$cRow} => {$terrID}, isMatch TERR_HCP_XREF {$isMatch} ", EOL;

这是echo句子的结果:

14:44:46 Load from Excel QXR_2015_Q3_PFE_V8_FINAL.xlsx file
HCP.ID A2 => 139810, TERRITORY.ID B2 => 453, isMatch TERR_HCP_XREF FALSE
HCP.ID A3 => 139810, TERRITORY.ID B3 => 560, isMatch TERR_HCP_XREF FALSE
HCP.ID A4 => 135453, TERRITORY.ID B4 => 442, isMatch TERR_HCP_XREF FALSE
HCP.ID A5 => 115075, TERRITORY.ID B5 => 445, isMatch TERR_HCP_XREF TRUE
Call time to read Workbook was 59.0086 seconds
14:45:45 Current memory usage: 409.5 MB

但由于列在运行脚本后没有值,因此无法正常工作,为什么?我的代码有什么问题?我在这里错过了什么吗?

0 个答案:

没有答案