From ab4c6602cf4bd483c719f1a2228233bed96b9884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Salmij=C3=A4rvi?= Date: Fri, 3 Jan 2020 23:34:10 +0200 Subject: [PATCH] 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". --- src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php b/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php index f460c0f1..f148b7c3 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php @@ -1137,13 +1137,13 @@ class Worksheet extends WriterPart case 'n': // Numeric //force a decimal to be written if the type is float 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) { $cellValue = $cellValue . '.0'; } } - // force point as decimal separator in case current locale uses comma - $objWriter->writeElement('v', str_replace(',', '.', $cellValue)); + $objWriter->writeElement('v', $cellValue); break; case 'b': // Boolean