1

PHPExcel 1.7.8マニュアルのセルキャッシュのすべての方法を試しましたが、どれも機能しません。約30MBの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」オプションをスキップしました。私はそれを試しました、そしてそれはキャッシュを始めました。ただし、256MBのメモリが使用可能な30MBのファイルでのキャッシュプロセス中にメモリが不足します。エラーは次のとおりです。

 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
4

1 に答える 1

0

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.

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.

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.

于 2012-12-01T17:45:38.677 に答える