PHPExcel用完了256,512和1024MB的RAM
我不明白。XSLX表大约3MB,甚至1024MB的RAM还不足以让PHPExcel将其加载到内存中?
我可能在这里做了一些可怕的错误:
function ReadXlsxTableIntoArray($theFilePath){ require_once('PHPExcel/Classes/PHPExcel.php'); $inputFileType = 'Excel2007'; $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objReader->setReadDataOnly(true); $objPHPExcel = $objReader->load($theFilePath); $rowIterator = $objPHPExcel->getActiveSheet()->getRowIterator(); $arrayData = $arrayOriginalColumnNames = $arrayColumnNames = array(); foreach($rowIterator as $row){ $cellIterator = $row->getCellIterator(); $cellIterator->setIterateOnlyExistingCells(false); // Loop all cells, even if it is not set if(1 == $row->getRowIndex ()) { foreach ($cellIterator as $cell) { $value = $cell->getCalculatedValue(); $arrayOriginalColumnNames[] = $value; // let's remove the diacritique $value = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $value); // and white spaces $valueExploded = explode(' ', $value); $value = ''; // capitalize the first letter of each word foreach ($valueExploded as $word) { $value .= ucfirst($word); } $arrayColumnNames[] = $value; } continue; } else { $rowIndex = $row->getRowIndex(); reset($arrayColumnNames); foreach ($cellIterator as $cell) { $arrayData[$rowIndex][current($arrayColumnNames)] = $cell->getCalculatedValue(); next($arrayColumnNames); } } } return array($arrayOriginalColumnNames, $arrayColumnNames, $arrayData);}
上面的函数将数据从excel表读取到数组。
有什么建议?
起初,我允许PHP使用256MB的RAM。这还不够。然后我把数量增加了一倍,然后尝试了1024MB。它仍然因内存不足而出现错误
幕布斯6054654
幕布斯7119047