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 97b3b21
Show file tree
Hide file tree
Showing 2 changed files with 25 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 && preg_match('/@(?=(?:[^"]*"[^"]*")*[^"]*\Z)/', $format) === 1) {
return str_replace('"', '', preg_replace('/@(?=(?:[^"]*"[^"]*")*[^"]*\Z)/', $value, $format));
}

return (string) $value;
}

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

0 comments on commit 97b3b21

Please sign in to comment.