[英]Cannot get cell caching to work in PHPExcel
我已經嘗試了PHPExcel 1.7.8手冊中的每種方法進行單元格緩存,但是沒有任何效果。 每次嘗試加載大約30 MB的Excel文件時,我仍然會用完內存。
這是我的代碼:
ini_set('memory_limit', '256M'); // Up from default 32MB
require MODULES_DIR . '/PHPExcel.php';
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_discISAM;
$cacheSettings = array('dir' => '/usr/local/tmp');
PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
$inputFileType = PHPExcel_IOFactory::identify($dir . $source_file);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($dir . $source_file);
$total_sheets = $objPHPExcel->getSheetCount();
$allSheetName = $objPHPExcel->getSheetNames();
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$headingsArray = $objWorksheet->rangeToArray('A1:'.$highestColumn.'1',null, true, true, true);
$headingsArray = $headingsArray[1];
$r = -1;
$namedDataArray = array();
for ($row = 2; $row <= $highestRow; ++$row) {
$dataRow = $objWorksheet->rangeToArray('A'.$row.':'.$highestColumn.$row,null, true, true, true);
if ((isset($dataRow[$row]['A'])) && ($dataRow[$row]['A'] > '')) {
++$r;
foreach($headingsArray as $columnKey => $columnHeading) {
$namedDataArray[$r][$columnHeading] = $dataRow[$row][$columnKey];
}
}
}
我已經嘗試了所有的單元緩存機制,一直到“ cache_to_sqlite3”,但是它們都不起作用。
有人可以告訴我我在做什么錯嗎?
編輯:顯然我跳過了“ cache_to_sqlite”選項。 我試過了,它開始緩存。 但是,它在30 MB文件(具有256MB可用內存)的緩存過程中仍會用完內存。 這是錯誤:
Fatal error: Uncaught exception 'Exception' with message 'out of memory' in modules/PHPExcel/CachedObjectStorage/SQLite.php:64 Stack trace: #0 modules/PHPExcel/CachedObjectStorage/SQLite.php(81): PHPExcel_CachedObjectStorage_SQLite->_storeData() #1 modules/PHPExcel/Worksheet.php(1123): PHPExcel_CachedObjectStorage_SQLite->addCacheData('X2498702', Object(PHPExcel_Cell)) #2 modules/PHPExcel/Reader/Excel5.php(3549): PHPExcel_Worksheet->getCell('X2498702') #3 modules/PHPExcel/Reader/Excel5.php(894): PHPExcel_Reader_Excel5->_readLabelSst() #4 modules/updater.inc.php(1478): PHPExcel_Reader_Excel5->load('modules/p...') #5 modules/updater.php(204): Updater->process_xls('prods.xls') #6 {main} thrown in modules/PHPExcel/CachedObjectStorage/SQLite.php on line 64
單元緩存不能消除內存使用:它可以減少內存使用。 顯然,您仍然沒有足夠的PHP內存來處理這么大的工作簿。
一個可能的問題是對單元格'X2498702'的引用... Excel BIFF文件(由Excel5 Reader加載的類型)的上限為65536行,因此,如果讀者嘗試加載,此處顯然出現了非常錯誤的情況行2498702中的單元格。問題不在於單元格緩存,而是Excel5閱讀器查找了可能被誤解或該Excel文件中不應該存在的數據。
您能否將此特定文件的副本(如果出於機密性考慮)上傳到PHPExcel網站,以便我們進行查看並嘗試確定到底出了什么問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.