From 8f7c2fd4645ffebdb7d194742534c755579f4c10 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 3 Aug 2015 00:33:29 +0100 Subject: [PATCH] Additional work on number format masks --- Classes/PHPExcel/Style/NumberFormat.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Classes/PHPExcel/Style/NumberFormat.php b/Classes/PHPExcel/Style/NumberFormat.php index 92869bf..f517df3 100644 --- a/Classes/PHPExcel/Style/NumberFormat.php +++ b/Classes/PHPExcel/Style/NumberFormat.php @@ -590,8 +590,9 @@ class PHPExcel_Style_NumberFormat extends PHPExcel_Style_Supervisor implements P 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); @@ -628,6 +629,10 @@ class PHPExcel_Style_NumberFormat extends PHPExcel_Style_Supervisor implements P 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; @@ -648,15 +653,6 @@ class PHPExcel_Style_NumberFormat extends PHPExcel_Style_Supervisor implements P 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('/(?