2

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

所以它的工作非常出色:)

4

1 回答 1

3

首先查看 PHPExcel 文档中有关单元缓存的部分:这是一种在处理较大的电子表格时减少 PHPExcel 内存需求的方法,并且正是为此目的而实现的。

于 2012-11-30T07:24:35.360 回答