diff --git a/docs/references/features-cross-reference.md b/docs/references/features-cross-reference.md
index a1b1e012d0..7ab9d068c6 100644
--- a/docs/references/features-cross-reference.md
+++ b/docs/references/features-cross-reference.md
@@ -906,7 +906,7 @@
|
|
|
- |
+ ● |
|
|
|
diff --git a/samples/46_ReadHtml.php b/samples/46_ReadHtml.php
new file mode 100644
index 0000000000..838d286822
--- /dev/null
+++ b/samples/46_ReadHtml.php
@@ -0,0 +1,19 @@
+load($html);
+
+$helper->logRead('Html', $html, $callStartTime);
+
+// Save
+$helper->write($objPHPExcel, __FILE__);
diff --git a/samples/templates/46readHtml.html b/samples/templates/46readHtml.html
new file mode 100644
index 0000000000..56f745dd86
--- /dev/null
+++ b/samples/templates/46readHtml.html
@@ -0,0 +1,130 @@
+
+
+
+
+
+ Competency List
+
+
+
+
+ Color Name |
+ HEX |
+ Color |
+
+
+
+ Black |
+ #000000 |
+ |
+
+
+
+ Blue |
+ #0000FF |
+ |
+
+
+
+
+ Green |
+ #008000 |
+ |
+
+
+
+ Cyan |
+ #00FFFF |
+ |
+
+
+
+ Purple |
+ #800080 |
+ |
+
+
+
+
+ Grey |
+ #808080 |
+ |
+
+
+
+ SkyBlue |
+ #87CEEB |
+ |
+
+
+
+
+ Brown |
+ #A52A2A |
+ |
+
+
+
+ Silver |
+ #C0C0C0 |
+ |
+
+
+
+ Chocolate |
+ #D2691E |
+ |
+
+
+
+ Tan |
+ #D2B48C |
+ |
+
+
+
+
+ Violet |
+ #EE82EE |
+ |
+
+
+
+
+ Red |
+ #FF0000 |
+ |
+
+
+
+ Pink |
+ #FFC0CB |
+ |
+
+
+
+ Gold |
+ #FFD700 |
+ |
+
+
+
+ Yellow |
+ #FFFF00 |
+ |
+
+
+
+ LightYellow |
+ #FFFFE0 |
+ |
+
+
+
+ White |
+ #FFFFFF |
+ |
+
+
+
+
diff --git a/src/PhpSpreadsheet/Reader/Html.php b/src/PhpSpreadsheet/Reader/Html.php
index 4db753b559..f77ef7a813 100644
--- a/src/PhpSpreadsheet/Reader/Html.php
+++ b/src/PhpSpreadsheet/Reader/Html.php
@@ -442,6 +442,9 @@ protected function processDomElement(DOMNode $element, Worksheet $sheet, &$row,
case 'td':
$this->processDomElement($child, $sheet, $row, $column, $cellContent);
+ // apply inline style
+ $this->applyInlineStyle($sheet, $row, $column, $attributeArray);
+
while (isset($this->rowspan[$column . $row])) {
++$column;
}
@@ -584,4 +587,56 @@ public function securityScan($xml)
return $xml;
}
+
+ /**
+ * Apply inline css inline style.
+ *
+ * NOTES :
+ * Currently only intended for td & th element,
+ * and only takes 'background-color' and 'color'; property with HEX color
+ *
+ * TODO :
+ * - Implement to other propertie, such as border
+ *
+ * @param Worksheet $sheet
+ * @param array $attributeArray
+ * @param int $row
+ * @param string $column
+ */
+ private function applyInlineStyle(&$sheet, $row, $column, $attributeArray)
+ {
+ if (!isset($attributeArray['style'])) {
+ return;
+ }
+
+ $supported_styles = ['background-color', 'color'];
+
+ // add color styles (background & text) from dom element,currently support : td & th, using ONLY inline css style with RGB color
+ $styles = explode(';', $attributeArray['style']);
+ foreach ($styles as $st) {
+ $value = explode(':', $st);
+
+ if (empty(trim($value[0])) || !in_array(trim($value[0]), $supported_styles)) {
+ continue;
+ }
+
+ //check if has #, so we can get clean hex
+ if (substr(trim($value[1]), 0, 1) == '#') {
+ $style_color = substr(trim($value[1]), 1);
+ }
+
+ if (empty($style_color)) {
+ continue;
+ }
+
+ switch (trim($value[0])) {
+ case 'background-color':
+ $sheet->getStyle($column . $row)->applyFromArray(['fill' => ['type' => Fill::FILL_SOLID, 'color' => ['rgb' => "{$style_color}"]]]);
+ break;
+ case 'color':
+ $sheet->getStyle($column . $row)->applyFromArray(['font' => ['color' => ['rgb' => "$style_color}"]]]);
+ break;
+ }
+ }
+ }
}