Best effort to support invalid colspan values in HTML reader
Closes #878
This commit is contained in:
parent
d6b3514431
commit
785705b712
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue