Additional work on number format masks

This commit is contained in:
MarkBaker 2015-08-03 00:33:46 +01:00
parent 7c0208bd26
commit 21f5db0ca5
1 changed files with 9 additions and 10 deletions

View File

@ -592,8 +592,9 @@ class NumberFormat extends Supervisor implements \PHPExcel\IComparable
return $value; 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); $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) // 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); $sections = preg_split('/(;)(?=(?:[^"]|"[^"]*")*$)/u', $format);
@ -630,6 +631,10 @@ class NumberFormat extends Supervisor implements \PHPExcel\IComparable
break; 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 // Save format with color information for later use below
$formatColor = $format; $formatColor = $format;
@ -650,15 +655,6 @@ class NumberFormat extends Supervisor implements \PHPExcel\IComparable
if ($format === self::FORMAT_CURRENCY_EUR_SIMPLE) { if ($format === self::FORMAT_CURRENCY_EUR_SIMPLE) {
$value = 'EUR ' . sprintf('%1.2f', $value); $value = 'EUR ' . sprintf('%1.2f', $value);
} else { } 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('/(?<!\\\\)\"/', '', $format);
// $format = str_replace(array('\\"', '*'), array('"', ''), $format);
// Some non-number strings are quoted, so we'll get rid of the quotes, likewise any positional * symbols // Some non-number strings are quoted, so we'll get rid of the quotes, likewise any positional * symbols
$format = str_replace(array('"', '*'), '', $format); $format = str_replace(array('"', '*'), '', $format);
@ -744,6 +740,9 @@ class NumberFormat extends Supervisor implements \PHPExcel\IComparable
} }
} }
// Escape any escaped slashes to a single slash
$format = preg_replace("/\\\\/u", '\\', $format);
// Additional formatting provided by callback function // Additional formatting provided by callback function
if ($callBack !== null) { if ($callBack !== null) {
list($writerInstance, $function) = $callBack; list($writerInstance, $function) = $callBack;