From adf6a18805f2daf1c9e920f8303b18f75cd235c9 Mon Sep 17 00:00:00 2001 From: Owen Leibman Date: Wed, 28 Apr 2021 06:56:52 -0700 Subject: [PATCH 1/3] Fix for Issue 2029 (Invalid Cell Coordinate A-1) Fix for #2021. When Html Reader encounters an embedded table, it tries to shift it up a row. It obviously should not attempt to shift it above row 1. @danmodini reported the problem, and suggests the correct solution. This PR implements that and adds a test case. --- src/PhpSpreadsheet/Reader/Html.php | 2 +- .../Reader/Html/Issue2029Test.php | 116 ++++++++++++++++++ 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 tests/PhpSpreadsheetTests/Reader/Html/Issue2029Test.php diff --git a/src/PhpSpreadsheet/Reader/Html.php b/src/PhpSpreadsheet/Reader/Html.php index f235f9b1b1..8705286fbb 100644 --- a/src/PhpSpreadsheet/Reader/Html.php +++ b/src/PhpSpreadsheet/Reader/Html.php @@ -469,7 +469,7 @@ private function processDomElementTable(Worksheet $sheet, int &$row, string &$co if ($child->nodeName === 'table') { $this->flushCell($sheet, $column, $row, $cellContent); $column = $this->setTableStartColumn($column); - if ($this->tableLevel > 1) { + if ($this->tableLevel > 1 && $row > 1) { --$row; } $this->processDomElement($child, $sheet, $row, $column, $cellContent); diff --git a/tests/PhpSpreadsheetTests/Reader/Html/Issue2029Test.php b/tests/PhpSpreadsheetTests/Reader/Html/Issue2029Test.php new file mode 100644 index 0000000000..7f54e1c348 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Html/Issue2029Test.php @@ -0,0 +1,116 @@ + + + + + Declaracion en Linea + + + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + +
CUIT:
Período
Secuencia:
Contribuyente:
+
+
+ + + + + + + + + + + + + + + + + + + + + +
+ CUIL + + Apellido y Nombre + + Obra Social + + Corresponde Reducción? +
+ 12345678901 + + EMILIANO ZAPATA SALAZAR + + 101208 + + Yes +
+ 23456789012 + + FRANCISCO PANCHO VILLA + + 101208 + + No +
+ + + +EOF; + $filename = 'tests/data/Reader/HTML/csv_with_angle_bracket.csv'; + $reader = new Html(); + $spreadsheet = $reader->loadFromString($content); + $sheet = $spreadsheet->getActiveSheet(); + self::assertSame('CUIT:', $sheet->getCell('A1')->getValue()); + self::assertSame('30-53914190-9', $sheet->getCell('B1')->getValue()); + self::assertSame('Contribuyente:', $sheet->getCell('A4')->getValue()); + self::assertSame('Apellido y Nombre', $sheet->getCell('B9')->getValue()); + self::assertEquals('101208', $sheet->getCell('C10')->getValue()); + self::assertEquals('Yes', $sheet->getCell('D10')->getValue()); + self::assertEquals('23456789012', $sheet->getCell('A11')->getValue()); + self::assertEquals('No', $sheet->getCell('D11')->getValue()); + } +} From ec02de8a29d5eb2dc73a91c9e78973ed4fef8786 Mon Sep 17 00:00:00 2001 From: Owen Leibman Date: Wed, 28 Apr 2021 07:33:34 -0700 Subject: [PATCH 2/3] Remove Dead Assignment from Test Scrutinizer. --- tests/PhpSpreadsheetTests/Reader/Html/Issue2029Test.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/PhpSpreadsheetTests/Reader/Html/Issue2029Test.php b/tests/PhpSpreadsheetTests/Reader/Html/Issue2029Test.php index 7f54e1c348..08cdbc257f 100644 --- a/tests/PhpSpreadsheetTests/Reader/Html/Issue2029Test.php +++ b/tests/PhpSpreadsheetTests/Reader/Html/Issue2029Test.php @@ -100,7 +100,6 @@ public function testIssue2029(): void EOF; - $filename = 'tests/data/Reader/HTML/csv_with_angle_bracket.csv'; $reader = new Html(); $spreadsheet = $reader->loadFromString($content); $sheet = $spreadsheet->getActiveSheet(); From c43d636793a51afe8b7ed1b867af2ca80be75f77 Mon Sep 17 00:00:00 2001 From: Owen Leibman Date: Wed, 28 Apr 2021 10:06:42 -0700 Subject: [PATCH 3/3] Two Minor Additional Problems Performing some additional testing, I found that Html Reader cannot handle inline column width or row height set in points rather than pixels (and HTML writer with useInlineCss generates these values in points). It also doesn't handle border style when the border width (which it ignores) is omitted. Fixed and added tests. --- src/PhpSpreadsheet/Reader/Html.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/PhpSpreadsheet/Reader/Html.php b/src/PhpSpreadsheet/Reader/Html.php index 8705286fbb..7301616b23 100644 --- a/src/PhpSpreadsheet/Reader/Html.php +++ b/src/PhpSpreadsheet/Reader/Html.php @@ -878,14 +878,14 @@ private function applyInlineStyle(&$sheet, $row, $column, $attributeArray): void case 'width': $sheet->getColumnDimension($column)->setWidth( - str_replace('px', '', $styleValue) + str_replace(['px', 'pt'], '', $styleValue) ); break; case 'height': $sheet->getRowDimension($row)->setRowHeight( - str_replace('px', '', $styleValue) + str_replace(['px', 'pt'], '', $styleValue) ); break; @@ -1009,7 +1009,15 @@ private function setBorderStyle(Style $cellStyle, $styleValue, $type): void $borderStyle = Border::BORDER_NONE; $color = null; } else { - [, $borderStyle, $color] = explode(' ', $styleValue); + $borderArray = explode(' ', $styleValue); + $borderCount = count($borderArray); + if ($borderCount >= 3) { + $borderStyle = $borderArray[1]; + $color = $borderArray[2]; + } else { + $borderStyle = $borderArray[0]; + $color = $borderArray[1] ?? null; + } } $cellStyle->applyFromArray([