Skip to content

Commit 138638a

Browse files
author
MarkBaker
committed
Ensure that selected worksheet is correctly set from Gnumeric Reader
1 parent 2af0b66 commit 138638a

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org).
1313

1414
### Changed
1515

16-
- Gnumeric Reader now loads number formatting for cells
16+
- Gnumeric Reader now loads number formatting for cells.
17+
- Gnumeric Reader now correctly identifies selected worksheet.
1718

1819
### Deprecated
1920

src/PhpSpreadsheet/Reader/Gnumeric.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,8 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
284284
$row = (int) $cellAttributes->Row + 1;
285285
$column = (int) $cellAttributes->Col;
286286

287-
if ($row > $maxRow) {
288-
$maxRow = $row;
289-
}
290-
if ($column > $maxCol) {
291-
$maxCol = $column;
292-
}
287+
$maxRow = max($maxRow, $row);
288+
$maxCol = max($maxCol, $column);
293289

294290
$column = Coordinate::stringFromColumnIndex($column + 1);
295291

@@ -318,10 +314,21 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
318314

319315
$this->processDefinedNames($gnmXML);
320316

317+
$this->setSelectedSheet($gnmXML);
318+
321319
// Return
322320
return $this->spreadsheet;
323321
}
324322

323+
private function setSelectedSheet(SimpleXMLElement $gnmXML): void
324+
{
325+
if (isset($gnmXML->UIData)) {
326+
$attributes = self::testSimpleXml($gnmXML->UIData->attributes());
327+
$selectedSheet = (int) $attributes['SelectedTab'];
328+
$this->spreadsheet->setActiveSheetIndex($selectedSheet);
329+
}
330+
}
331+
325332
private function processMergedCells(?SimpleXMLElement $sheet): void
326333
{
327334
// Handle Merged Cells in this worksheet

0 commit comments

Comments
 (0)