Skip to content

Commit 64bf016

Browse files
committed
Fix for Xls writer wrong cells and sheet selection.
1 parent f734783 commit 64bf016

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/PhpSpreadsheet/Writer/Xls/Worksheet.php

+10
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ public function close()
281281
{
282282
$phpSheet = $this->phpSheet;
283283

284+
// Storing selected cells and active sheet because it changes while parsing cells with formulas.
285+
$selectedCells = $this->phpSheet->getSelectedCells();
286+
$activeSheetIndex = $this->phpSheet->getParent()->getActiveSheetIndex();
287+
284288
// Write BOF record
285289
$this->storeBof(0x0010);
286290

@@ -459,6 +463,9 @@ public function close()
459463
// Append
460464
$this->writeMsoDrawing();
461465

466+
// Restoring active sheet.
467+
$this->phpSheet->getParent()->setActiveSheetIndex($activeSheetIndex);
468+
462469
// Write WINDOW2 record
463470
$this->writeWindow2();
464471

@@ -471,6 +478,9 @@ public function close()
471478
$this->writePanes();
472479
}
473480

481+
// Restoring selected cells.
482+
$this->phpSheet->setSelectedCells($selectedCells);
483+
474484
// Write SELECTION record
475485
$this->writeSelection();
476486

0 commit comments

Comments
 (0)