Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Xlsx reader overriding manually set number format with builtin number format #1805

Merged
merged 1 commit into from Jan 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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