Skip to content

Commit 1b71e75

Browse files
author
MarkBaker
committed
Performance Experiment for the Xls Writer, to avoid creating empty cells; and should also be slightly faster
1 parent b399c09 commit 1b71e75

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/PhpSpreadsheet/Writer/Xls.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
66
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
7+
use PhpOffice\PhpSpreadsheet\Cell\Cell;
78
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
89
use PhpOffice\PhpSpreadsheet\RichText\RichText;
910
use PhpOffice\PhpSpreadsheet\RichText\Run;
@@ -161,8 +162,9 @@ public function save($filename, int $flags = 0): void
161162

162163
// add fonts from rich text eleemnts
163164
for ($i = 0; $i < $countSheets; ++$i) {
164-
foreach ($this->writerWorksheets[$i]->phpSheet->getCoordinates() as $coordinate) {
165-
$cell = $this->writerWorksheets[$i]->phpSheet->getCell($coordinate);
165+
foreach ($this->writerWorksheets[$i]->phpSheet->getCellCollection()->getCoordinates() as $coordinate) {
166+
/** @var Cell $cell */
167+
$cell = $this->writerWorksheets[$i]->phpSheet->getCellCollection()->get($coordinate);
166168
$cVal = $cell->getValue();
167169
if ($cVal instanceof RichText) {
168170
$elements = $cVal->getRichTextElements();

src/PhpSpreadsheet/Writer/Xls/Worksheet.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PhpOffice\PhpSpreadsheet\Writer\Xls;
44

55
use GdImage;
6+
use PhpOffice\PhpSpreadsheet\Cell\Cell;
67
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
78
use PhpOffice\PhpSpreadsheet\Cell\DataType;
89
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
@@ -406,8 +407,9 @@ public function close(): void
406407
}
407408

408409
// Write Cells
409-
foreach ($phpSheet->getCoordinates() as $coordinate) {
410-
$cell = $phpSheet->getCell($coordinate);
410+
foreach ($phpSheet->getCellCollection()->getSortedCoordinates() as $coordinate) {
411+
/** @var Cell $cell */
412+
$cell = $phpSheet->getCellCollection()->get($coordinate);
411413
$row = $cell->getRow() - 1;
412414
$column = Coordinate::columnIndexFromString($cell->getColumn()) - 1;
413415

src/PhpSpreadsheet/Writer/Xlsx/StringTable.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx;
44

5+
use PhpOffice\PhpSpreadsheet\Cell\Cell;
56
use PhpOffice\PhpSpreadsheet\Cell\DataType;
67
use PhpOffice\PhpSpreadsheet\RichText\RichText;
78
use PhpOffice\PhpSpreadsheet\RichText\Run;
@@ -36,6 +37,7 @@ public function createStringTable(Worksheet $worksheet, $existingTable = null)
3637

3738
// Loop through cells
3839
foreach ($worksheet->getCellCollection()->getCoordinates() as $coordinate) {
40+
/** @var Cell $cell */
3941
$cell = $worksheet->getCellCollection()->get($coordinate);
4042
$cellValue = $cell->getValue();
4143
if (

0 commit comments

Comments
 (0)