小编ser*_*983的帖子

PHPExcel仅在XLS文件中超出内存使用量

我在处理XLS文件时遇到了PHPExcel的内存问题.我必须处理相当大的文件(50k到200k行和9-10列),所以我不得不使用ReadFilters来解决内存问题.

但是,尽管它在XLSX文件中运行良好,但是使用混合的后台进程和一些简单的块大小计算,我无法使其与XLS文件一起使用.

这是一切爆炸的代码:

Class ExcelReadFilter implements PHPExcel_Reader_IReadFilter
{
    private $startRow = 0;
    private $endRow = 0;

    public function setRows($startRow, $chunkSize) {
        $this->startRow    = $startRow;
        $this->endRow        = $startRow + $chunkSize;
    }

    public function readCell($column, $row, $worksheetName = '') {
        if ( ($row >= $this->startRow && $row < $this->endRow) ) {
            return true;
        }
        return false;
    }
}

PHPExcel_Settings::setCacheStorageMethod( PHPExcel_CachedObjectStorageFactory::cache_in_memory_serialized );

....
$filter = new ExcelReadFilter();
$filter->setRows($desde, $cuantas);

$reader = PHPExcel_IOFactory::createReader($this->file_type);   

$reader->setLoadSheetsOnly($sheet_name);    
$reader->setReadDataOnly(false);    
$reader->setReadFilter($filter);

$chunk = $reader->load($this->file);
$chunk->setActiveSheetIndexByName($sheet_name);

$active_sheet = $chunk->getActiveSheet();
$rowIterator …
Run Code Online (Sandbox Code Playgroud)

php phpexcel phpexcelreader

8
推荐指数
1
解决办法
1414
查看次数

标签 统计

php ×1

phpexcel ×1

phpexcelreader ×1