From de230fa8994470185302f2b378c4b04186df7bcd Mon Sep 17 00:00:00 2001 From: oleibman Date: Thu, 5 Aug 2021 08:40:13 -0700 Subject: [PATCH] Html Reader Comments (#2235) * Html Reader Comments See issue #2234. Html Reader processes Comment as comment, then processes it as part of cell contents. Change to only do the first. Comment Test checks that comment read by Html Reader is okay, but neglects to check the value of the cell to which the comment is attached. Added that check. * Disconnect Worksheets ... at end of test. --- src/PhpSpreadsheet/Reader/Html.php | 3 ++- tests/PhpSpreadsheetTests/Functional/CommentsTest.php | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/PhpSpreadsheet/Reader/Html.php b/src/PhpSpreadsheet/Reader/Html.php index 60bd7757..7bd1b31d 100644 --- a/src/PhpSpreadsheet/Reader/Html.php +++ b/src/PhpSpreadsheet/Reader/Html.php @@ -345,8 +345,9 @@ class Html extends BaseReader $sheet->getComment($column . $row) ->getText() ->createTextRun($child->textContent); + } else { + $this->processDomElement($child, $sheet, $row, $column, $cellContent); } - $this->processDomElement($child, $sheet, $row, $column, $cellContent); if (isset($this->formats[$child->nodeName])) { $sheet->getStyle($column . $row)->applyFromArray($this->formats[$child->nodeName]); diff --git a/tests/PhpSpreadsheetTests/Functional/CommentsTest.php b/tests/PhpSpreadsheetTests/Functional/CommentsTest.php index d82f7f96..03be3e00 100644 --- a/tests/PhpSpreadsheetTests/Functional/CommentsTest.php +++ b/tests/PhpSpreadsheetTests/Functional/CommentsTest.php @@ -40,8 +40,9 @@ class CommentsTest extends AbstractFunctional $commentCoordinate = key($commentsLoaded); self::assertSame('E10', $commentCoordinate); + self::assertSame('Comment', $sheet->getCell('E10')->getValue()); $comment = $commentsLoaded[$commentCoordinate]; - self::assertEquals('Comment to test', (string) $comment); + self::assertSame('Comment to test', (string) $comment); $commentClone = clone $comment; self::assertEquals($comment, $commentClone); self::assertNotSame($comment, $commentClone); @@ -51,5 +52,7 @@ class CommentsTest extends AbstractFunctional $comment->setAlignment(Alignment::HORIZONTAL_RIGHT); self::assertEquals(Alignment::HORIZONTAL_RIGHT, $comment->getAlignment()); } + $spreadsheet->disconnectWorksheets(); + $reloadedSpreadsheet->disconnectWorksheets(); } }