Skip to content

Commit 4d5a482

Browse files
authored
Merge pull request #2820 from PHPOffice/Performance-Coordinates-2
Performance tweaks to calculating column string from index
2 parents 32efe0e + 55f03a5 commit 4d5a482

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/PhpSpreadsheet/Cell/Coordinate.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,15 @@ public static function columnIndexFromString($columnAddress)
324324
public static function stringFromColumnIndex($columnIndex)
325325
{
326326
static $indexCache = [];
327+
static $lookupCache = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ';
327328

328329
if (!isset($indexCache[$columnIndex])) {
329330
$indexValue = $columnIndex;
330331
$base26 = '';
331332
do {
332333
$characterValue = ($indexValue % 26) ?: 26;
333334
$indexValue = ($indexValue - $characterValue) / 26;
334-
$base26 = chr($characterValue + 64) . $base26;
335+
$base26 = $lookupCache[$characterValue] . $base26;
335336
} while ($indexValue > 0);
336337
$indexCache[$columnIndex] = $base26;
337338
}

0 commit comments

Comments
 (0)