Skip to content

Commit

Permalink
Fix Xlsx reader overriding manually set number format with builtin nu…
Browse files Browse the repository at this point in the history
…mber format (#1805)
  • Loading branch information
rvanvelzen committed Jan 28, 2021
1 parent e1ed52e commit 87c8e95
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/PhpSpreadsheet/Reader/Xlsx.php
Expand Up @@ -488,7 +488,7 @@ public function load($pFilename)
}
if (!$this->readDataOnly && $xmlStyles) {
foreach ($xmlStyles->cellXfs->xf as $xf) {
$numFmt = NumberFormat::FORMAT_GENERAL;
$numFmt = null;

if ($xf['numFmtId']) {
if (isset($numFmts)) {
Expand All @@ -503,6 +503,7 @@ public function load($pFilename)
// But there's a lot of naughty homebrew xlsx writers that do use "reserved" id values that aren't actually used
// So we make allowance for them rather than lose formatting masks
if (
$numFmt === null &&
(int) $xf['numFmtId'] < 164 &&
NumberFormat::builtInFormatCode((int) $xf['numFmtId']) !== ''
) {
Expand All @@ -515,7 +516,7 @@ public function load($pFilename)
}

$style = (object) [
'numFmt' => $numFmt,
'numFmt' => $numFmt === null ? NumberFormat::FORMAT_GENERAL : $numFmt,
'font' => $xmlStyles->fonts->font[(int) ($xf['fontId'])],
'fill' => $xmlStyles->fills->fill[(int) ($xf['fillId'])],
'border' => $xmlStyles->borders->border[(int) ($xf['borderId'])],
Expand Down

0 comments on commit 87c8e95

Please sign in to comment.