PHPExcel仅返回空单元格值

时间:2014-02-07 08:40:53

标签: php phpexcel

我从这些代码开始

$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
$cacheSettings = array( 'memoryCacheSize' => '128MB');
$cacheEnabled = PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
if (!$cacheEnabled)
{
            # WARNING - Cache to php temp not enableable ###" . PHP_EOL;
}
$inputFileType = PHPExcel_IOFactory::identify($file_path);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);  
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($file_path);
$objWorksheet   = $objPHPExcel->setActiveSheetIndex(0); 

然后

 $highestRow = $objWorksheet->getHighestRow();

返回2560.好的,我已经填充了2560行的excel。

然后我循环

for ($x =1; $x<=$highestRow; $x++)  // here $x plus plus ...
{
   $ean                = $objWorksheet->getCellByColumnAndRow(15, $row)->getValue();
   $description        = $objWorksheet->getCellByColumnAndRow(13, $row)->getValue();
   echo $ean .":" .$description . PHP_EOL;
}

但每行都是空的,只打印2560“:”。

所以我想要整行,因为我真的无法理解为什么返回的值是空的!每张单张格子,从A到BC,从1到2560,都有一些值。

为什么所有细胞看起来都是空的? 如何调试?

1 个答案:

答案 0 :(得分:2)

您使用$row引用了getCellByColumnAndRow()来电中的行,但由于您的for循环正在使用$x

无论

for ($x =1; $x<=$highestRow; $x++)
{
   $ean                = $objWorksheet->getCellByColumnAndRow(15, $x)->getValue();
   $description        = $objWorksheet->getCellByColumnAndRow(13, $x)->getValue();
   echo $ean .":" .$description . PHP_EOL;
}

for ($row =1; $row<=$highestRow; $row++)
{
   $ean                = $objWorksheet->getCellByColumnAndRow(15, $row)->getValue();
   $description        = $objWorksheet->getCellByColumnAndRow(13, $row)->getValue();
   echo $ean .":" .$description . PHP_EOL;
}