相关疑难解决方法(0)

如何将工作表的列数作为整数(28)而不是Excel-字母("AB")?

鉴于:

$this->objPHPExcelReader = PHPExcel_IOFactory::createReaderForFile($this->config['file']);
$this->objPHPExcelReader->setLoadSheetsOnly(array($this->config['worksheet']));
$this->objPHPExcelReader->setReadDataOnly(true);
$this->objPHPExcel = $this->objPHPExcelReader->load($this->config['file']);
Run Code Online (Sandbox Code Playgroud)

我可以迭代这样的行,但它很慢,即在3MB的Excel文件中,工作表有"EL"列,每行大约需要1秒:

foreach ($this->objPHPExcel->setActiveSheetIndex(0)->getRowIterator() as $row)
{
    $dataset = array();
    $cellIterator = $row->getCellIterator();
    $cellIterator->setIterateOnlyExistingCells(false);
    foreach ($cellIterator as $cell)
    {
        if (!is_null($cell))
        {
            $dataset[] = $cell->getCalculatedValue();
        }
    }
    $this->datasets[] = $dataset;
}
Run Code Online (Sandbox Code Playgroud)

当我像这样迭代时,它显着更快(在30秒内大约2000行),但我必须将字母例如"EL"转换为数字:

$highestColumm = $this->objPHPExcel->setActiveSheetIndex(0)->getHighestColumn(); // e.g. "EL"
$highestRow = $this->objPHPExcel->setActiveSheetIndex(0)->getHighestRow();

$number_of_columns = 150; // TODO: figure out how to get the number of cols as int
for ($row = 1; $row < $highestRow …
Run Code Online (Sandbox Code Playgroud)

php phpexcel

32
推荐指数
1
解决办法
6万
查看次数

标签 统计

php ×1

phpexcel ×1