diff --git a/src/PhpSpreadsheet/Style/NumberFormat.php b/src/PhpSpreadsheet/Style/NumberFormat.php index 98de69dd..c199fffd 100644 --- a/src/PhpSpreadsheet/Style/NumberFormat.php +++ b/src/PhpSpreadsheet/Style/NumberFormat.php @@ -592,8 +592,9 @@ class NumberFormat extends Supervisor implements \PHPExcel\IComparable return $value; } - // Convert any escaped characters to quoted strings, e.g. (\T to "T") + // Convert any other escaped characters to quoted strings, e.g. (\T to "T") $format = preg_replace('/(\\\(.))(?=(?:[^"]|"[^"]*")*$)/u', '"${2}"', $format); + // Get the sections, there can be up to four sections, separated with a semi-colon (but only if not a quoted literal) $sections = preg_split('/(;)(?=(?:[^"]|"[^"]*")*$)/u', $format); @@ -630,6 +631,10 @@ class NumberFormat extends Supervisor implements \PHPExcel\IComparable break; } + // In Excel formats, "_" is used to add spacing, + // The following character indicates the size of the spacing, which we can't do in HTML, so we just use a standard space + $format = preg_replace('/_./', ' ', $format); + // Save format with color information for later use below $formatColor = $format; @@ -650,15 +655,6 @@ class NumberFormat extends Supervisor implements \PHPExcel\IComparable if ($format === self::FORMAT_CURRENCY_EUR_SIMPLE) { $value = 'EUR ' . sprintf('%1.2f', $value); } else { - // In Excel formats, "_" is used to add spacing, which we can't do in HTML - $format = preg_replace('/_./', '', $format); - - // Some non-number characters are escaped with \, which we don't need - $format = preg_replace("/\\\\/", '', $format); -// Handle escaped characters, such as \" to display a literal " or \\ to display a literal \ -// $format = preg_replace('/(?