PhpSpreadsheet Reading WorkBook Data Example #04
Get a List of the Worksheets in a WorkBook
load($inputFileName);
echo '
';
echo 'Reading the number of Worksheets in the WorkBook
';
/* Use the PhpSpreadsheet object's getSheetCount() method to get a count of the number of WorkSheets in the WorkBook */
$sheetCount = $spreadsheet->getSheetCount();
echo 'There ', (($sheetCount == 1) ? 'is' : 'are'), ' ', $sheetCount, ' WorkSheet', (($sheetCount == 1) ? '' : 's'), ' in the WorkBook
';
echo 'Reading the names of Worksheets in the WorkBook
';
/* Use the PhpSpreadsheet object's getSheetNames() method to get an array listing the names/titles of the WorkSheets in the WorkBook */
$sheetNames = $spreadsheet->getSheetNames();
foreach ($sheetNames as $sheetIndex => $sheetName) {
echo 'WorkSheet #', $sheetIndex, ' is named "', $sheetName, '"
';
}
?>