Best effort to support invalid colspan values in HTML reader

Closes #878
This commit is contained in:
Mahmoud Abdo 2019-02-11 15:06:39 +03:00 committed by Adrien Crivelli
parent d6b3514431
commit 785705b712
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
4 changed files with 30 additions and 5 deletions

View File

@ -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) - 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 - 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) - 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 ## [1.8.2] - 2019-07-08

View File

@ -502,10 +502,10 @@ class Html extends BaseReader
if (isset($attributeArray['rowspan'], $attributeArray['colspan'])) { if (isset($attributeArray['rowspan'], $attributeArray['colspan'])) {
//create merging rowspan and colspan //create merging rowspan and colspan
$columnTo = $column; $columnTo = $column;
for ($i = 0; $i < $attributeArray['colspan'] - 1; ++$i) { for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) {
++$columnTo; ++$columnTo;
} }
$range = $column . $row . ':' . $columnTo . ($row + $attributeArray['rowspan'] - 1); $range = $column . $row . ':' . $columnTo . ($row + (int) $attributeArray['rowspan'] - 1);
foreach (Coordinate::extractAllCellReferencesInRange($range) as $value) { foreach (Coordinate::extractAllCellReferencesInRange($range) as $value) {
$this->rowspan[$value] = true; $this->rowspan[$value] = true;
} }
@ -513,7 +513,7 @@ class Html extends BaseReader
$column = $columnTo; $column = $columnTo;
} elseif (isset($attributeArray['rowspan'])) { } elseif (isset($attributeArray['rowspan'])) {
//create merging 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) { foreach (Coordinate::extractAllCellReferencesInRange($range) as $value) {
$this->rowspan[$value] = true; $this->rowspan[$value] = true;
} }
@ -521,7 +521,7 @@ class Html extends BaseReader
} elseif (isset($attributeArray['colspan'])) { } elseif (isset($attributeArray['colspan'])) {
//create merging colspan //create merging colspan
$columnTo = $column; $columnTo = $column;
for ($i = 0; $i < $attributeArray['colspan'] - 1; ++$i) { for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) {
++$columnTo; ++$columnTo;
} }
$sheet->mergeCells($column . $row . ':' . $columnTo . $row); $sheet->mergeCells($column . $row . ':' . $columnTo . $row);

View File

@ -321,4 +321,14 @@ class HtmlTest extends TestCase
{ {
return (new Html())->load($filename); 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);
}
} }

View File

@ -0,0 +1,14 @@
<table>
<tbody>
<tr>
<td>A1</td>
<td>B1</td>
<td>C1</td>
<td>D1</td>
</tr>
<tr>
<td colspan='3"'>A2 with invalid colspan</td>
<td>D2<td>
</tr>
</tbody>
</table>