From 7e12575d867ce9a8a071c899ee59e21b90bab7cb Mon Sep 17 00:00:00 2001 From: Dhaval Purohit Date: Wed, 13 May 2020 13:56:49 +0530 Subject: [PATCH] Borders are complete even on rowspanned columns using HTML reader Fixed #1455 Closes #1473 --- CHANGELOG.md | 1 + src/PhpSpreadsheet/Reader/Html.php | 21 ++++++++++++- tests/PhpSpreadsheetTests/Reader/HtmlTest.php | 31 +++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d45ebac..cd682780 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). ### Fixed - WEBSERVICE is HTTP client agnostic and must be configured via `Settings::setHttpClient()` [#1562](https://github.com/PHPOffice/PhpSpreadsheet/issues/1562) +- Borders were not complete on rowspanned columns using HTML reader [#1473](https://github.com/PHPOffice/PhpSpreadsheet/pull/1473) ### Changed diff --git a/src/PhpSpreadsheet/Reader/Html.php b/src/PhpSpreadsheet/Reader/Html.php index 2fe85b6f..d59e4744 100644 --- a/src/PhpSpreadsheet/Reader/Html.php +++ b/src/PhpSpreadsheet/Reader/Html.php @@ -682,7 +682,26 @@ class Html extends BaseReader return; } - $cellStyle = $sheet->getStyle($column . $row); + if (isset($attributeArray['rowspan'], $attributeArray['colspan'])) { + $columnTo = $column; + for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) { + ++$columnTo; + } + $range = $column . $row . ':' . $columnTo . ($row + (int) $attributeArray['rowspan'] - 1); + $cellStyle = $sheet->getStyle($range); + } elseif (isset($attributeArray['rowspan'])) { + $range = $column . $row . ':' . $column . ($row + (int) $attributeArray['rowspan'] - 1); + $cellStyle = $sheet->getStyle($range); + } elseif (isset($attributeArray['colspan'])) { + $columnTo = $column; + for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) { + ++$columnTo; + } + $range = $column . $row . ':' . $columnTo . $row; + $cellStyle = $sheet->getStyle($range); + } else { + $cellStyle = $sheet->getStyle($column . $row); + } // add color styles (background & text) from dom element,currently support : td & th, using ONLY inline css style with RGB color $styles = explode(';', $attributeArray['style']); diff --git a/tests/PhpSpreadsheetTests/Reader/HtmlTest.php b/tests/PhpSpreadsheetTests/Reader/HtmlTest.php index b0994a33..636aaa94 100644 --- a/tests/PhpSpreadsheetTests/Reader/HtmlTest.php +++ b/tests/PhpSpreadsheetTests/Reader/HtmlTest.php @@ -424,4 +424,35 @@ class HtmlTest extends TestCase self::assertEquals(10, $style->getAlignment()->getIndent()); unlink($filename); } + + public function testBorderWithRowspanAndColspan(): void + { + $html = ' + + + + + + + +
NOT SPANNEDSPANNED
NOT SPANNED
'; + + $reader = new Html(); + $spreadsheet = $reader->loadFromString($html); + $firstSheet = $spreadsheet->getSheet(0); + $style = $firstSheet->getStyle('B1:C2'); + + $borders = $style->getBorders(); + + $totalBorders = [ + $borders->getTop(), + $borders->getLeft(), + $borders->getBottom(), + $borders->getRight(), + ]; + + foreach ($totalBorders as $border) { + self::assertEquals(Border::BORDER_THIN, $border->getBorderStyle()); + } + } }