Borders are complete even on rowspanned columns using HTML reader

Fixed #1455
Closes #1473
This commit is contained in:
Dhaval Purohit 2020-05-13 13:56:49 +05:30 committed by Adrien Crivelli
parent 7cb4884b96
commit 7e12575d86
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
3 changed files with 52 additions and 1 deletions

View File

@ -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

View File

@ -682,7 +682,26 @@ class Html extends BaseReader
return;
}
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']);

View File

@ -424,4 +424,35 @@ class HtmlTest extends TestCase
self::assertEquals(10, $style->getAlignment()->getIndent());
unlink($filename);
}
public function testBorderWithRowspanAndColspan(): void
{
$html = '<table>
<tr>
<td style="border: 1px solid black;">NOT SPANNED</td>
<td rowspan="2" colspan="2" style="border: 1px solid black;">SPANNED</td>
</tr>
<tr>
<td style="border: 1px solid black;">NOT SPANNED</td>
</tr>
</table>';
$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());
}
}
}