2014-02-07 222 views
0

我開始與這些代碼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好了,我的Excel與人口2560行。

然後我循環

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的每張單頁紙都充滿了一些價值。

爲什麼所有的單元格看起來都是空的? 如何調試?

回答

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; 
} 
任何地方所定義
+0

該死的,多麼愚蠢...... – realtebo