简体   繁体   English

无法使单元格缓存在PHPExcel中工作

[英]Cannot get cell caching to work in PHPExcel

I've tried every method in the PHPExcel 1.7.8 manual for cell caching, but none work. 我已经尝试了PHPExcel 1.7.8手册中的每种方法进行单元格缓存,但是没有任何效果。 I still run out of memory every time I try to load an Excel file of about 30 MB. 每次尝试加载大约30 MB的Excel文件时,我仍然会用完内存。

Here is my code: 这是我的代码:

    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];
            }
        }
    }

I've tried every one of the cell caching mechanisms all the way down to "cache_to_sqlite3" but none of them work. 我已经尝试了所有的单元缓存机制,一直到“ cache_to_sqlite3”,但是它们都不起作用。

Can someone tell me what I am doing wrong here? 有人可以告诉我我在做什么错吗?

EDIT: Apparently I skipped over the "cache_to_sqlite" option. 编辑:显然我跳过了“ cache_to_sqlite”选项。 I tried that and it started caching. 我试过了,它开始缓存。 However, it still runs out of memory during the caching process on a 30 MB file with 256MB of memory available. 但是,它在30 MB文件(具有256MB可用内存)的缓存过程中仍会用完内存。 Here is the error: 这是错误:

 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

Cell caching doesn't eliminate memory usage: it reduces it. 单元缓存不能消除内存使用:它可以减少内存使用。 Clearly you still don't have enough PHP memory to handle a workbook this large. 显然,您仍然没有足够的PHP内存来处理这么大的工作簿。

One possible issue is the reference to cell 'X2498702'... Excel BIFF files (of the type loaded by the Excel5 Reader) have an upper limit of 65536 rows, so something has clearly gone very wrong here if the reader is trying to load a cell in row 2498702. The problem isn't cell caching, it's the Excel5 Reader finding data that either it's misinterpreting, or that shouldn't exist in this Excel file. 一个可能的问题是对单元格'X2498702'的引用... Excel BIFF文件(由Excel5 Reader加载的类型)的上限为65536行,因此,如果读者尝试加载,此处显然出现了非常错误的情况行2498702中的单元格。问题不在于单元格缓存,而是Excel5阅读器查找了可能被误解或该Excel文件中不应该存在的数据。

Can you please upload a copy of this particular file (if confidentiality permist) to the PHPExcel website so we can take a look and try to ascertain exactly what is going wrong. 您能否将此特定文件的副本(如果出于机密性考虑)上传到PHPExcel网站,以便我们进行查看并尝试确定到底出了什么问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM