PHPExcel创建XLSX重载ram

时间:2012-11-29 22:07:12

标签: php phpexcel

我需要知道在使用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();

所以这很有效:)

1 个答案:

答案 0 :(得分:3)

首先查看PHPExcel文档中有关Cell Cacheing的部分:这是一种在使用更大的电子表格时减少PHPExcel的内存需求的方法,并且是为了这个目的而实现的。