gpt4 book ai didi

PHPExcel 创建 XLS 重载 ram

转载 作者:行者123 更新时间:2023-12-04 05:21:35 25 4
gpt4 key购买 nike

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

所以它的工作非常好:)

最佳答案

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

关于PHPExcel 创建 XLS 重载 ram,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13635633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com