我已經創建了一個腳本,並且出現以下錯誤。如果將內存大小升級到7g仍然是錯誤。所以我試圖追加10000條記錄並保存,併爲下一個10000去解決它,工作,但仍然得到錯誤。致命錯誤:允許的xxx字節內存大小已耗盡Php excel
是否有任何方法來刷新工作簿或其他方法?
Thnx!
的awnser:
PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
$cacheMethod = PHPExcel_CachedObjectStorageFactory:: cache_to_discISAM;
$cacheSettings = array(
'dir' => '/home/domains/xxxx.nl/public_html/xxxxx'
);
require_once 'PHPExcel.php';
require_once 'PHPExcel/Writer/Excel2007.php';
require_once 'PHPExcel/IOFactory.php';
$counter = $result->num_rows;//159920
$spreadsheet = new PHPExcel();
$spreadsheet->setActiveSheetIndex(0);
$worksheet = $spreadsheet->getActiveSheet();
//header
$worksheet->setCellValueExplicit('A' . 1, 'Filename', PHPExcel_Cell_DataType::TYPE_STRING);
etc
etc
$rownr = 2;
$counterN = 0;
while ($row = mysqli_fetch_assoc($result)) {
$worksheet->setCellValueExplicit('A' . $rownr, utf8_encode($row['filename']), PHPExcel_Cell_DataType::TYPE_STRING);
etc
etc
if($counterN == 10000){
$objWriter = new PHPExcel_Writer_Excel2007($spreadsheet);
$objWriter->save('test.xlsx');
$objPHPExcel = PHPExcel_IOFactory::load("test.xlsx");
$objPHPExcel->setActiveSheetIndex(0);
$row = $objPHPExcel->getActiveSheet()->getHighestRow()+1;
$counterN = 0;
}
$counterN++;
}
$objWriter = new PHPExcel_Writer_Excel2007($spreadsheet);
$objWriter->save('test.xlsx');
我得到相同的錯誤,試圖輸出一個4k行的Excel,我認爲PHPExcel有超過2個3k記錄的東西泄漏內存 –
http://stackoverflow.com/questions/4817651/phpexcel-runs- 256-512-也-124mb-ram –
謝謝,我試過了($ objReader-> setReadDataOnly(true);)但這不起作用... – Bas