要读取xlsx大文件,我使用部分读取(chunkReadFilter),但如果文件位于引用文件开头的单元格的公式单元格中,则返回错误#N / A.我认为因为从文件读取另一个数据块并且不再存在对公式的单元格的访问。如何解决它。我的代码示例:
$oExcel = new Excel();
$objReader = $oExcel->CreateObjectExcel2007();
for ($iList=0;$iList<$list_count;$iList++){
$iAllStringsTotal += ($row_start - 1);
$iAllStringsCurrentList = ($row_start - 1);
for($iStartRow = $row_start; $iStartRow <= $ExelInfo[$iList]['totalRows']; $iStartRow += $iChunkSize) {
$objReader = $oExcel->SetCreateReader();
$oChunkFilter = new chunkReadFilter();
$objReader->setReadFilter($oChunkFilter);
$oChunkFilter->setRows($iStartRow,$iChunkSize);
$objReader->setReadFilter($oChunkFilter);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($files['path']);
$objPHPExcel->setActiveSheetIndex($iList);
$sFromCell = 'A'.$iStartRow;
$aData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,false,$sFromCell);
// free memory
unset($objPHPExcel);
unset($objReader);
unset($oChunkFilter);
// parse data
foreach ($aData as $sKey => $aValue) {
$iAllStringsCurrentList += 1;
$iAllStringsTotal += 1;
// this code parsing data
}
// real data rows
if (count($aData) < $iChunkSize) {
unset($aData);
break;
}
unset($aData);
}
}