diff --git a/CHANGELOG.md b/CHANGELOG.md index d3ce9b5b..1f08b073 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - COUPNUM should not return zero when settlement is in the last period - [Issue #1020](https://github.com/PHPOffice/PhpSpreadsheet/issues/1020) and [PR #1021](https://github.com/PHPOffice/PhpSpreadsheet/pull/1021) - Fix handling of named ranges referencing sheets with spaces or "!" in their title - Cover `getSheetByName()` with tests for name with quote and spaces - [#739](https://github.com/PHPOffice/PhpSpreadsheet/issues/739) +- Best effort to support invalid colspan values in HTML reader - [878](https://github.com/PHPOffice/PhpSpreadsheet/pull/878) ## [1.8.2] - 2019-07-08 diff --git a/src/PhpSpreadsheet/Reader/Html.php b/src/PhpSpreadsheet/Reader/Html.php index d599424d..ff2c909e 100644 --- a/src/PhpSpreadsheet/Reader/Html.php +++ b/src/PhpSpreadsheet/Reader/Html.php @@ -502,10 +502,10 @@ class Html extends BaseReader if (isset($attributeArray['rowspan'], $attributeArray['colspan'])) { //create merging rowspan and colspan $columnTo = $column; - for ($i = 0; $i < $attributeArray['colspan'] - 1; ++$i) { + for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) { ++$columnTo; } - $range = $column . $row . ':' . $columnTo . ($row + $attributeArray['rowspan'] - 1); + $range = $column . $row . ':' . $columnTo . ($row + (int) $attributeArray['rowspan'] - 1); foreach (Coordinate::extractAllCellReferencesInRange($range) as $value) { $this->rowspan[$value] = true; } @@ -513,7 +513,7 @@ class Html extends BaseReader $column = $columnTo; } elseif (isset($attributeArray['rowspan'])) { //create merging rowspan - $range = $column . $row . ':' . $column . ($row + $attributeArray['rowspan'] - 1); + $range = $column . $row . ':' . $column . ($row + (int) $attributeArray['rowspan'] - 1); foreach (Coordinate::extractAllCellReferencesInRange($range) as $value) { $this->rowspan[$value] = true; } @@ -521,7 +521,7 @@ class Html extends BaseReader } elseif (isset($attributeArray['colspan'])) { //create merging colspan $columnTo = $column; - for ($i = 0; $i < $attributeArray['colspan'] - 1; ++$i) { + for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) { ++$columnTo; } $sheet->mergeCells($column . $row . ':' . $columnTo . $row); diff --git a/tests/PhpSpreadsheetTests/Reader/HtmlTest.php b/tests/PhpSpreadsheetTests/Reader/HtmlTest.php index 415f562a..e8b00f1a 100644 --- a/tests/PhpSpreadsheetTests/Reader/HtmlTest.php +++ b/tests/PhpSpreadsheetTests/Reader/HtmlTest.php @@ -33,7 +33,7 @@ class HtmlTest extends TestCase /** * @dataProvider providerCanReadVerySmallFile * - * @param bool $expected + * @param bool $expected * @param string $content */ public function testCanReadVerySmallFile($expected, $content) @@ -321,4 +321,14 @@ class HtmlTest extends TestCase { return (new Html())->load($filename); } + + public function testRowspanInRendering() + { + $filename = './data/Reader/HTML/rowspan.html'; + $reader = new Html(); + $spreadsheet = $reader->load($filename); + + $actual = $spreadsheet->getActiveSheet()->getMergeCells(); + self::assertSame(['A2:C2' => 'A2:C2'], $actual); + } } diff --git a/tests/data/Reader/HTML/rowspan.html b/tests/data/Reader/HTML/rowspan.html new file mode 100644 index 00000000..c748c8e3 --- /dev/null +++ b/tests/data/Reader/HTML/rowspan.html @@ -0,0 +1,14 @@ + + + + + + + + + + + + +
A1B1C1D1
A2 with invalid colspanD2 +