Looping through worksheets with PHPExcel

前端 未结 3 921
情深已故
情深已故 2021-02-05 08:07

I\'m using the PHPExcel library to read an Excel file and perform processing on it. I want to loop through each worksheet. I checked the documentation and all I could find was

3条回答
  •  臣服心动
    2021-02-05 08:40

    I think you can do this. Increment the active sheet until there aren't any left, then do what you want with each one:

    setReadDataOnly(true);
    
        $objPHPExcel = $objReader->load("test.xlsx");
    
        $i = 0;
        while ($objPHPExcel->setActiveSheetIndex($i)){
    
            $objWorksheet = $objPHPExcel->getActiveSheet();
            //now do whatever you want with the active sheet
            ...
            $i++;
    
        }
    
        ...
    
    ?>
    

提交回复
热议问题