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數據文件導出.
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的php excel 单元格类型,设置20个单元格类型后,PhpExcel停止工作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 昌平北清橡树湾东侧是什么回迁房?
- 下一篇: 定制橱柜十大品牌有哪些?