php excel 单元格类型,设置20个单元格类型后,PhpExcel停止工作
PHPExcel分配了相當(dāng)多的內(nèi)存
雖然PHPExcel是一個(gè)漂亮的庫,但使用它可能需要為PHP分配大量?jī)?nèi)存.
根據(jù)this thread,只有5個(gè)單元可以渲染6 MB的內(nèi)存使用量:
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提供了減少內(nèi)存占用的方法,但在我的情況下,所有減少都變得太小了. This page on github提供了PHPExcel緩存管理選項(xiàng)的詳細(xì)信息.例如,此設(shè)置序列化和GZIPs工作表的單元格結(jié)構(gòu):
$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的測(cè)量結(jié)果
我檢測(cè)了PHPExcel示例文件[01simple.PHP] [5]并做了一些快速測(cè)試.
消耗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);
}
如果多次執(zhí)行此片段不變,則每個(gè)片段消耗大約4 MB.
檢查您的應(yīng)用在邏輯上是正確的
為確保您的應(yīng)用程序在邏輯上正確,我建議首先增加PHP內(nèi)存:
ini_set('memory_limit','32M');
在我的情況下,我必須導(dǎo)出到在線評(píng)估應(yīng)用程序的導(dǎo)出結(jié)果數(shù)據(jù).雖然水平方向的單元格少于100個(gè),但我需要導(dǎo)出多達(dá)10,000個(gè)行.雖然單元格的數(shù)量很大,但我的每個(gè)單元格都包含3個(gè)字符的數(shù)字或字符串 – 沒有公式,沒有樣式.
如果存在強(qiáng)大的內(nèi)存限制或大型電子表格
在我的例子中,沒有一個(gè)緩存選項(xiàng)減少了所需的數(shù)量.此外,應(yīng)用程序的運(yùn)行時(shí)間也大大增加.
最后我不得不切換到老式的CSV數(shù)據(jù)文件導(dǎo)出.
與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的php excel 单元格类型,设置20个单元格类型后,PhpExcel停止工作的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 昌平北清橡树湾东侧是什么回迁房?
- 下一篇: php 输出excepion内容,带有消