PHPExcel导入超过500行

时间:2017-12-20 01:11:41

标签: php phpexcel

我有可以将上传的csv文件保存在数据库中的代码。但问题是它只能在超过1000行中保存100-200行。我有一个想法是逐批保存行而不是整个行,但我不知道如何编写它。

require_once 'PHPexcel/PHPExcel.php';
    $objPHPExcel = PHPExcel_IOFactory::load($file);

    foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
        $worksheetTitle     = $worksheet->getTitle();
        $highestRow         = $worksheet->getHighestRow();
        $highestColumn      = $worksheet->getHighestColumn();
        $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);

        for ($row = 2; $row <= $highestRow; ++ $row) {
            $val=array();
            for ($col = 0; $col < $highestColumnIndex; ++ $col) {
                $cell = $worksheet->getCellByColumnAndRow($col, $row);
                $val[] = $cell->getValue();
            }

        }
}

0 个答案:

没有答案