Fix to negative number handling with complex number format masks, so that the sign only appears once

This commit is contained in:
MarkBaker 2015-01-23 15:40:54 +00:00
parent dc137c293a
commit d778b41524
2 changed files with 12 additions and 6 deletions

View File

@ -498,12 +498,14 @@ class PHPExcel_Style_NumberFormat extends PHPExcel_Style_Supervisor implements P
}
}
private static function _complexNumberFormatMask($number, $mask) {
private static function _complexNumberFormatMask($number, $mask, $level = 0) {
$sign = ($number < 0.0);
$number = abs($number);
if (strpos($mask,'.') !== false) {
$numbers = explode('.', $number . '.0');
$masks = explode('.', $mask . '.0');
$result1 = self::_complexNumberFormatMask($numbers[0], $masks[0]);
$result2 = strrev(self::_complexNumberFormatMask(strrev($numbers[1]), strrev($masks[1])));
$result1 = self::_complexNumberFormatMask($numbers[0], $masks[0], 1);
$result2 = strrev(self::_complexNumberFormatMask(strrev($numbers[1]), strrev($masks[1])), 1);
return $result1 . '.' . $result2;
}
@ -531,7 +533,7 @@ class PHPExcel_Style_NumberFormat extends PHPExcel_Style_Supervisor implements P
$result = $number;
}
return $result;
return (($sign) ? '-' : '') . $result;
}
/**
@ -614,6 +616,9 @@ class PHPExcel_Style_NumberFormat extends PHPExcel_Style_Supervisor implements P
// 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
$format = str_replace(array('"', '*'), '', $format);

View File

@ -32,3 +32,4 @@
123456789, '(000) 0-0000-000', "(001) 2-3456-789"
123456789, '0 (+00) 0000 00 00 00', "0 (+00) 0123 45 67 89"
123456789, '0000:00:00', "12345:67:89"
-123456789, '0000:00:00', "-12345:67:89"