diff --git a/src/PhpSpreadsheet/Writer/Html.php b/src/PhpSpreadsheet/Writer/Html.php index 53cd86bea..5c907149e 100644 --- a/src/PhpSpreadsheet/Writer/Html.php +++ b/src/PhpSpreadsheet/Writer/Html.php @@ -1360,7 +1360,7 @@ class Html extends BaseWriter * @param null|Cell|string $cell * @param array|string $cssClass */ - private function generateRowCellData(Worksheet $worksheet, $cell, &$cssClass, string $cellType): string + private function generateRowCellData(Worksheet $worksheet, $cell, &$cssClass): string { $cellData = ' '; if ($cell instanceof Cell) { @@ -1384,14 +1384,10 @@ class Html extends BaseWriter $cssClass .= ' style' . $cell->getXfIndex(); $cssClass .= ' ' . $cell->getDataType(); } elseif (is_array($cssClass)) { - if ($cellType == 'th') { - if (isset($this->cssStyles['th.style' . $cell->getXfIndex()])) { - $cssClass = array_merge($cssClass, $this->cssStyles['th.style' . $cell->getXfIndex()]); - } - } else { - if (isset($this->cssStyles['td.style' . $cell->getXfIndex()])) { - $cssClass = array_merge($cssClass, $this->cssStyles['td.style' . $cell->getXfIndex()]); - } + $index = $cell->getXfIndex(); + $styleIndex = 'td.style' . $index . ', th.style' . $index; + if (isset($this->cssStyles[$styleIndex])) { + $cssClass = array_merge($cssClass, $this->cssStyles[$styleIndex]); } // General horizontal alignment: Actual horizontal alignment depends on dataType @@ -1511,7 +1507,7 @@ class Html extends BaseWriter [$cell, $cssClass, $coordinate] = $this->generateRowCellCss($worksheet, $cellAddress, $row, $colNum); // Cell Data - $cellData = $this->generateRowCellData($worksheet, $cell, $cssClass, $cellType); + $cellData = $this->generateRowCellData($worksheet, $cell, $cssClass); // Hyperlink? if ($worksheet->hyperlinkExists($coordinate) && !$worksheet->getHyperlink($coordinate)->isInternal()) { diff --git a/tests/PhpSpreadsheetTests/Writer/Html/Issue3678Test.php b/tests/PhpSpreadsheetTests/Writer/Html/Issue3678Test.php new file mode 100644 index 000000000..5c0a7cd02 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Writer/Html/Issue3678Test.php @@ -0,0 +1,37 @@ +getActiveSheet(); + $sheet->getCell('A1')->setValue(1); + $styleArray = [ + 'fill' => [ + 'fillType' => Fill::FILL_SOLID, + 'color' => ['rgb' => 'FFFF00'], + ], + ]; + $sheet->getStyle('A1')->applyFromArray($styleArray); + $style1 = "vertical-align:bottom; border-bottom:none #000000; border-top:none #000000; border-left:none #000000; border-right:none #000000; color:#000000; font-family:'Calibri'; font-size:11pt; background-color:#FFFF00"; + $style2 = $style1 . '; text-align:right; width:42pt'; + $writer = new Html($spreadsheet); + $html = $writer->generateHtmlAll(); + self::assertStringContainsString('td.style1, th.style1 { ' . $style1 . ' }', $html); + self::assertStringContainsString('