diff --git a/src/PhpSpreadsheet/Style/NumberFormat/Formatter.php b/src/PhpSpreadsheet/Style/NumberFormat/Formatter.php index 03b002e533..d6d274ea92 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 && strpos($format, NumberFormat::FORMAT_TEXT) !== false) { + return str_replace([NumberFormat::FORMAT_TEXT, '"'], [(string) $value, ''], $format); + } + return (string) $value; } diff --git a/tests/data/Style/NumberFormat.php b/tests/data/Style/NumberFormat.php index 4bd6b48118..edcda4da57 100644 --- a/tests/data/Style/NumberFormat.php +++ b/tests/data/Style/NumberFormat.php @@ -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 [