Fix Xlsx Writer's handling of decimal commas (#1282)

Perform the comma -> period substitution in Xlsx Writer writeCell()
before checking if the decimal value has a period in it. The previous
behavior led to decimals of the form "1,1" to become "1.1.0".
This commit is contained in:
Markus Salmijärvi 2020-01-03 23:34:10 +02:00 committed by Mark Baker
parent 9fab8900ef
commit ab4c6602cf
1 changed files with 3 additions and 3 deletions

View File

@ -1137,13 +1137,13 @@ class Worksheet extends WriterPart
case 'n': // Numeric case 'n': // Numeric
//force a decimal to be written if the type is float //force a decimal to be written if the type is float
if (is_float($cellValue)) { if (is_float($cellValue)) {
$cellValue = (string) $cellValue; // force point as decimal separator in case current locale uses comma
$cellValue = str_replace(',', '.', (string) $cellValue);
if (strpos($cellValue, '.') === false) { if (strpos($cellValue, '.') === false) {
$cellValue = $cellValue . '.0'; $cellValue = $cellValue . '.0';
} }
} }
// force point as decimal separator in case current locale uses comma $objWriter->writeElement('v', $cellValue);
$objWriter->writeElement('v', str_replace(',', '.', $cellValue));
break; break;
case 'b': // Boolean case 'b': // Boolean