Skip to content

Commit 7e12575

Browse files
dhaval247PowerKiKi
authored andcommitted
Borders are complete even on rowspanned columns using HTML reader
Fixed #1455 Closes #1473
1 parent 7cb4884 commit 7e12575

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
1414
### Fixed
1515

1616
- WEBSERVICE is HTTP client agnostic and must be configured via `Settings::setHttpClient()` [#1562](https://github.com/PHPOffice/PhpSpreadsheet/issues/1562)
17+
- Borders were not complete on rowspanned columns using HTML reader [#1473](https://github.com/PHPOffice/PhpSpreadsheet/pull/1473)
1718

1819
### Changed
1920

src/PhpSpreadsheet/Reader/Html.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,26 @@ private function applyInlineStyle(&$sheet, $row, $column, $attributeArray): void
682682
return;
683683
}
684684

685-
$cellStyle = $sheet->getStyle($column . $row);
685+
if (isset($attributeArray['rowspan'], $attributeArray['colspan'])) {
686+
$columnTo = $column;
687+
for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) {
688+
++$columnTo;
689+
}
690+
$range = $column . $row . ':' . $columnTo . ($row + (int) $attributeArray['rowspan'] - 1);
691+
$cellStyle = $sheet->getStyle($range);
692+
} elseif (isset($attributeArray['rowspan'])) {
693+
$range = $column . $row . ':' . $column . ($row + (int) $attributeArray['rowspan'] - 1);
694+
$cellStyle = $sheet->getStyle($range);
695+
} elseif (isset($attributeArray['colspan'])) {
696+
$columnTo = $column;
697+
for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) {
698+
++$columnTo;
699+
}
700+
$range = $column . $row . ':' . $columnTo . $row;
701+
$cellStyle = $sheet->getStyle($range);
702+
} else {
703+
$cellStyle = $sheet->getStyle($column . $row);
704+
}
686705

687706
// add color styles (background & text) from dom element,currently support : td & th, using ONLY inline css style with RGB color
688707
$styles = explode(';', $attributeArray['style']);

tests/PhpSpreadsheetTests/Reader/HtmlTest.php

+31
Original file line numberDiff line numberDiff line change
@@ -424,4 +424,35 @@ public function testTextIndentUseRowspan(): void
424424
self::assertEquals(10, $style->getAlignment()->getIndent());
425425
unlink($filename);
426426
}
427+
428+
public function testBorderWithRowspanAndColspan(): void
429+
{
430+
$html = '<table>
431+
<tr>
432+
<td style="border: 1px solid black;">NOT SPANNED</td>
433+
<td rowspan="2" colspan="2" style="border: 1px solid black;">SPANNED</td>
434+
</tr>
435+
<tr>
436+
<td style="border: 1px solid black;">NOT SPANNED</td>
437+
</tr>
438+
</table>';
439+
440+
$reader = new Html();
441+
$spreadsheet = $reader->loadFromString($html);
442+
$firstSheet = $spreadsheet->getSheet(0);
443+
$style = $firstSheet->getStyle('B1:C2');
444+
445+
$borders = $style->getBorders();
446+
447+
$totalBorders = [
448+
$borders->getTop(),
449+
$borders->getLeft(),
450+
$borders->getBottom(),
451+
$borders->getRight(),
452+
];
453+
454+
foreach ($totalBorders as $border) {
455+
self::assertEquals(Border::BORDER_THIN, $border->getBorderStyle());
456+
}
457+
}
427458
}

0 commit comments

Comments
 (0)