php excel 单元格类型,设置20个单元格类型后,PhpExcel停止工作

PHPExcel分配了相当多的内存

虽然PHPExcel是一个漂亮的库,但使用它可能需要为PHP分配大量内存.

根据this thread,只有5个单元可以渲染6 MB的内存使用量:

require_once 'PHP/PHPExcelSVN/PHPExcel/IOFactory.PHP';

$objPHPExcel = PHPExcel_IOFactory::load("PHP/tinytest.xlsx");

$objPHPExcel->setActiveSheetIndex(0);

$objPHPExcel->getActiveSheet()->setCellValue('D2',50);

echo $objPHPExcel->getActiveSheet()->getCell('D8')->getCalculatedValue() . "

";

echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";

?>

I get 6MB of memory usage.

虽然PHPExcel提供了减少内存占用的方法,但在我的情况下,所有减少都变得太小了. This page on github提供了PHPExcel缓存管理选项的详细信息.例如,此设置序列化和GZIPs工作表的单元格结构:

$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip;

PHPExcel_Settings::setCacheStorageMethod($cacheMethod);

Fatal error: Allowed memory size of xxx bytes exhausted (tried to

allocate yyy bytes) in zzz on line aaa

PHPExcel holds an “in memory” representation of a spreadsheet,so it

is susceptible to PHP’s memory limitations. The memory made available

to PHP can be increased by editing the value of the memorylimit

directive in your PHP.ini file,or by using iniset(‘memory_limit’,

‘128M’) within your code (ISP permitting);

Some Readers and Writers are faster than others,and they also use

differing amounts of memory. You can find some indication of the

relative performance and memory usage for the different Readers and

Writers,over the different versions of PHPExcel,here

07004

If you’ve already increased memory to a maximum,or can’t change your

memory limit,then this discussion on the board describes some of the

methods that can be applied to reduce the memory usage of your scripts

using PHPExcel

07005

PHP Excel的测量结果

我检测了PHPExcel示例文件[01simple.PHP] [5]并做了一些快速测试.

消耗92 KByte:

for( $n=0; $n<200; $n++ ) {

$objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A' . $n,'Miscellaneous glyphs');

}

消耗4164 KB:

for( $n=0; $n<200; $n++ ) {

$objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A' . $n,'Miscellaneous glyphs');

$objPHPExcel->getActiveSheet()->getStyle('A' . $n)->getAlignment()->setWrapText(true);

}

如果多次执行此片段不变,则每个片段消耗大约4 MB.

检查您的应用在逻辑上是正确的

为确保您的应用程序在逻辑上正确,我建议首先增加PHP内存:

ini_set('memory_limit','32M');

在我的情况下,我必须导出到在线评估应用程序的导出结果数据.虽然水平方向的单元格少于100个,但我需要导出多达10,000个行.虽然单元格的数量很大,但我的每个单元格都包含3个字符的数字或字符串 – 没有公式,没有样式.

如果存在强大的内存限制或大型电子表格

在我的例子中,没有一个缓存选项减少了所需的数量.此外,应用程序的运行时间也大大增加.

最后我不得不切换到老式的CSV数据文件导出.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值