Skip to content

Commit 8521820

Browse files
authored
Update Spreadsheet.php
1 parent ca12ffd commit 8521820

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/PhpSpreadsheet/Spreadsheet.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ public function addSheet(Worksheet $worksheet, ?int $sheetIndex = null, bool $re
608608
*/
609609
public function removeSheetByIndex(int $sheetIndex): void
610610
{
611-
$numSheets = $this->getSheetCount();
611+
$numSheets = count($this->workSheetCollection);
612612
if ($sheetIndex > $numSheets - 1) {
613613
throw new Exception(
614614
"You tried to remove a sheet by the out of bounds index: {$sheetIndex}. The actual number of sheets is {$numSheets}."
@@ -660,9 +660,10 @@ public function getAllSheets(): array
660660
*/
661661
public function getSheetByName(string $worksheetName): ?Worksheet
662662
{
663+
$worksheetCount = count($this->workSheetCollection);
663664
$trimWorksheetName = trim($worksheetName, "'");
664665

665-
for ($i = 0; $i < $this->getSheetCount(); ++$i) {
666+
for ($i = 0; $i < $wroksheetCount; ++$i) {
666667
if (strcasecmp($this->workSheetCollection[$i]->getTitle(), $trimWorksheetName) === 0) {
667668
return $this->workSheetCollection[$i];
668669
}
@@ -791,8 +792,8 @@ public function setActiveSheetIndexByName(string $worksheetName): Worksheet
791792
public function getSheetNames(): array
792793
{
793794
$returnValue = [];
794-
795-
for ($i = 0; $i < $this->getSheetCount(); ++$i) {
795+
$worksheetCount = $this->getSheetCount();
796+
for ($i = 0; $i < $worksheetCount; ++$i) {
796797
$returnValue[] = $this->getSheet($i)->getTitle();
797798
}
798799

0 commit comments

Comments
 (0)