PHPExcel - How can i read the Excel sheet row by row

前端 未结 4 1687
长发绾君心
长发绾君心 2020-12-11 16:41

How can i read Excel worksheet row by row using PHPExcel? I have a sheet contains more than 100000 rows, but i want to read only 500 rows.

$sheetData = $objP         


        
4条回答
  •  攒了一身酷
    2020-12-11 17:05

    You can load 500 rows or even setting start index by setting parameters directly to the getRowIterator function.

    $path = "Your File Path HERE";
    $fileObj = \PHPExcel_IOFactory::load( $path );
    $sheetObj = $fileObj->getActiveSheet();
    $startFrom = 50; //default value is 1
    $limit = 550; //default value is null
    foreach( $sheetObj->getRowIterator($startFrom, $limit) as $row ){
        foreach( $row->getCellIterator() as $cell ){
            $value = $cell->getCalculatedValue();
        }
    }
    

提交回复
热议问题