如何使用PHPExcel读取xlsx文件的第二页?
2022-08-30 17:40:22
我知道如何阅读我的xlsx电子表格并循环浏览第一张纸。
它有5张,我很难到达第一张以外的任何一张。
这是我使用的代码,它直接来自文档。您可以看到我试图利用setActiveSheet,但这引发了错误。Call to undefined method PHPExcel::setActiveSheet()
验证码:
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load("cmt_school_data.xlsx");
//$objPHPExcel->setActiveSheet(1);
$objWorksheet = $objPHPExcel->getActiveSheet();
echo '<table border=1>' . "\n";
foreach ($objWorksheet->getRowIterator() as $row) {
echo '<tr>' . "\n";
$cellIterator = $row->getCellIterator();
// This loops all cells, even if it is not set.
// By default, only cells that are set will be iterated.
$cellIterator->setIterateOnlyExistingCells(false);
foreach ($cellIterator as $cell) {
echo '<td>' . $cell->getValue() . '</td>' . "\n";
}
echo '</tr>' . "\n";
}
echo '</table>' . "\n";