diff --git a/src/PhpSpreadsheet/Style/NumberFormat/Formatter.php b/src/PhpSpreadsheet/Style/NumberFormat/Formatter.php index 03b002e533..a2650d1cc6 100644 --- a/src/PhpSpreadsheet/Style/NumberFormat/Formatter.php +++ b/src/PhpSpreadsheet/Style/NumberFormat/Formatter.php @@ -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; } diff --git a/tests/data/Style/NumberFormat.php b/tests/data/Style/NumberFormat.php index 4bd6b48118..9b43db345a 100644 --- a/tests/data/Style/NumberFormat.php +++ b/tests/data/Style/NumberFormat.php @@ -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 [