使用 PHPExcel 循环遍历工作表
我正在使用PHPExcel库来读取Excel文件并对其进行处理。我想遍历每个工作表。我检查了文档,我所能找到的只是更改活动工作表索引或仅加载指定的工作表。如何遍历所有工作表?
感谢您的任何帮助。
以下是文档的循环示例,以供参考:
<?php
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load("test.xlsx");
$objWorksheet = $objPHPExcel->getActiveSheet();
echo '<table>' . "\n";
foreach ($objWorksheet->getRowIterator() as $row) {
echo '<tr>' . "\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 '<td>' . $cell->getValue() . '</td>' . "\n";
}
echo '</tr>' . "\n";
}
echo '</table>' . "\n";
?>