Borders are complete even on rowspanned columns using HTML reader
Fixed #1455 Closes #1473
This commit is contained in:
parent
7cb4884b96
commit
7e12575d86
|
@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- WEBSERVICE is HTTP client agnostic and must be configured via `Settings::setHttpClient()` [#1562](https://github.com/PHPOffice/PhpSpreadsheet/issues/1562)
|
- 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
|
### Changed
|
||||||
|
|
||||||
|
|
|
@ -682,7 +682,26 @@ class Html extends BaseReader
|
||||||
return;
|
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
|
// add color styles (background & text) from dom element,currently support : td & th, using ONLY inline css style with RGB color
|
||||||
$styles = explode(';', $attributeArray['style']);
|
$styles = explode(';', $attributeArray['style']);
|
||||||
|
|
|
@ -424,4 +424,35 @@ class HtmlTest extends TestCase
|
||||||
self::assertEquals(10, $style->getAlignment()->getIndent());
|
self::assertEquals(10, $style->getAlignment()->getIndent());
|
||||||
unlink($filename);
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue