Skip to content

Commit

Permalink
Improved handling of @ format mask
Browse files Browse the repository at this point in the history
With some limitations remaining:
 - Still doesn't work in section 4
 - Doesn't work correctly if there is an @ in quotes, not recognised as a literal
  • Loading branch information
MarkBaker committed Feb 4, 2023
1 parent ad0b68c commit bb861d7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/PhpSpreadsheet/Style/NumberFormat/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public static function toFormattedString($value, $format, $callBack = null)
}
// For now we do not treat strings although section 4 of a format code affects strings
if (!is_numeric($value)) {
if (strpos($format, ';') === false && strpos($format, NumberFormat::FORMAT_TEXT) !== false) {
return str_replace([NumberFormat::FORMAT_TEXT, '"'], [(string) $value, ''], $format);
}

return (string) $value;
}

Expand Down
16 changes: 16 additions & 0 deletions tests/data/Style/NumberFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,22 @@
'test',
'_-€* #,##0.00_-;"-€"* #,##0.00_-;_-€* -??_-;_-@_-',
],
// String masks (ie. @)
[
'World',
'World',
'@',
],
[
'Hello World',
'World',
'Hello @',
],
[
'Hello World',
'World',
'"Hello "@',
],
// Named colours
// Simple color
[
Expand Down

0 comments on commit bb861d7

Please sign in to comment.