How do I read sheet two of an xlsx file with PHPExcel?

前端 未结 3 2098
时光取名叫无心
时光取名叫无心 2020-12-07 21:03

I know how to read my xlsx spreadsheet and loop through the first sheet.

It has 5 sheets and I am having trouble getting to any other than the first.

Here is

3条回答
  •  佛祖请我去吃肉
    2020-12-07 21:43

    Ok...the names are deceiving. setActiveSheetIndex also does a get so the solution was this

    $objReader = PHPExcel_IOFactory::createReader('Excel2007');
    $objReader->setReadDataOnly(true);
    $objPHPExcel = $objReader->load("cmt_school_data.xlsx");
    $objWorksheet = $objPHPExcel->setActiveSheetIndex(1);
    //objWorksheet = $objPHPExcel->getActiveSheet();
    echo '' . "\n";
    foreach ($objWorksheet->getRowIterator() as $row) {
      echo '' . "\n";
      $cellIterator = $row->getCellIterator();
      $cellIterator->setIterateOnlyExistingCells(false); // This loops all cells,
                                                         // even if it is not set.
                                                         // By default, only cells
                                                         // that are set will be
                                                         // iterated.
      foreach ($cellIterator as $cell) {
        echo '' . "\n";
      }
      echo '' . "\n";
    }
    echo '
    ' . $cell->getValue() . '
    ' . "\n";

提交回复
热议问题