我需要知道在使用 PHPEXEL 创建 XLS 时是否有减少内存使用的方法。这些文件大约有 15000 行。
我有这个脚本:
$payroll_incomes = $payroll_incomes->execute(null, Doctrine::HYDRATE_ARRAY);
$objPHPExcel->getActiveSheet()->fromArray($payroll_incomes[0], null, 'A1');
// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('INGRESOS');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="Ingresos.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output')
当我运行此脚本时,我收到此消息
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20 bytes) in /var/www/payroll/plugins/sfPhpExcelPlugin/lib/PHPExcel/PHPExcel/Worksheet.php on line 962
谢谢!!
更新
我添加了这行代码:
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
$cacheSettings = array( ' memoryCacheSize ' => '10KB');
PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
$objPHPExcel = new PHPExcel();
所以它的工作非常出色:)