PHPExcel阅读太慢 [英] PHPExcel reading too slow

查看:385
本文介绍了PHPExcel阅读太慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,这里有很多问题可以改善PHPExcel性能.但是所有这些都是关于写入数据的,而我的问题在于读取.

I know, there are lot's of questions here sbout improving PHPExcel performance. But all of them are about writing data, and my problem is in reading.

我的功能:

function parse($filename){
    $objPHPExcel = PHPExcel_IOFactory::load($filename); 
    $activeSheet = $objPHPExcel->getActiveSheet();
    $parsedData = array();
    $columnHeaders = array('order', 'ts', 'summ', 'name', 'quant', 'price', 'bccu');
    foreach ($activeSheet->getRowIterator() as $rkey => $row) {
        $cellIterator = $row->getCellIterator();
        foreach ($cellIterator  as $ckey => $cell) {
            $parsedData[$columnHeaders[$ckey]] = $cell->getCalculatedValue();
        }
    }
    return $parsedData;
}

文件包含约300行和7列.而且此脚本无法在30秒内运行.

The file contains ~300 rows and 7 columns. And this script fails to run in 30 seconds.

我该如何改善?

已使用

$objReader = PHPExcel_IOFactory::createReader("Excel2007");
$objPHPExcel = $objReader->load($filename); 

没有成功

推荐答案

如果已经定义了列,那么如何删除列迭代器呢?

If your columns are already defined, what about remove the column iterator?

尝试这样的事情:

foreach ($activeSheet->getRowIterator() as $rkey => $row) {
    $rowIndex = $row->getRowIndex ();
    $parsedData[$rowIndex]['order'] = $activeSheet->getCell('A' . $rowIndex);
    $parsedData[$rowIndex]['ts']    = $activeSheet->getCell('B' . $rowIndex);
    $parsedData[$rowIndex]['summ']  = $activeSheet->getCell('C' . $rowIndex);
    .
    .
    .
}

这篇关于PHPExcel阅读太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆