From 29fa2318a378a5c6dff3186cfd103aa26be54bfa Mon Sep 17 00:00:00 2001 From: Pouria Seyfi Date: Thu, 9 Mar 2023 03:17:05 +0330 Subject: [PATCH] Convert cell value to numbeic (float) in processDomElementDataFormat If we want to use data-format attribute in html, we have to cast cell value to float (number). because format not applied to string values. We should know excel put Leading apostrophes " ' " to numeric string values. Leading apostrophes force excel to treat the cell's contents as a text value. --- src/PhpSpreadsheet/Reader/Html.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/PhpSpreadsheet/Reader/Html.php b/src/PhpSpreadsheet/Reader/Html.php index 780cfec8a7..8046fcf021 100644 --- a/src/PhpSpreadsheet/Reader/Html.php +++ b/src/PhpSpreadsheet/Reader/Html.php @@ -560,6 +560,8 @@ private function processDomElementVAlign(Worksheet $sheet, int $row, string $col private function processDomElementDataFormat(Worksheet $sheet, int $row, string $column, array $attributeArray): void { if (isset($attributeArray['data-format'])) { + $value = $sheet->getCell($column . $row)->getValue(); + $sheet->setCellValue($column . $row, (float) $value); $sheet->getStyle($column . $row)->getNumberFormat()->setFormatCode($attributeArray['data-format']); } }