From 8ed6b209961ad821391c8796283c8755f7bada4a Mon Sep 17 00:00:00 2001 From: Owen Leibman Date: Sat, 21 Aug 2021 18:48:12 -0700 Subject: [PATCH] Process Comments in Sylk File Fixes issue #2276. --- src/PhpSpreadsheet/Reader/Slk.php | 9 ++++++++ .../Reader/Slk/SlkCommentsTest.php | 23 +++++++++++++++++++ tests/data/Reader/Slk/issue.2276.slk | 10 ++++++++ 3 files changed, 42 insertions(+) create mode 100644 tests/PhpSpreadsheetTests/Reader/Slk/SlkCommentsTest.php create mode 100644 tests/data/Reader/Slk/issue.2276.slk diff --git a/src/PhpSpreadsheet/Reader/Slk.php b/src/PhpSpreadsheet/Reader/Slk.php index 4e76a1616d..882aaefecd 100644 --- a/src/PhpSpreadsheet/Reader/Slk.php +++ b/src/PhpSpreadsheet/Reader/Slk.php @@ -299,6 +299,15 @@ private function processCRecord(array $rowData, Spreadsheet &$spreadsheet, strin case 'E': $this->processFormula($rowDatum, $hasCalculatedValue, $cellDataFormula, $row, $column); + break; + case 'A': + $comment = substr($rowDatum, 1); + $columnLetter = Coordinate::stringFromColumnIndex((int) $column); + $spreadsheet->getActiveSheet() + ->getComment("$columnLetter$row") + ->getText() + ->createText($comment); + break; } } diff --git a/tests/PhpSpreadsheetTests/Reader/Slk/SlkCommentsTest.php b/tests/PhpSpreadsheetTests/Reader/Slk/SlkCommentsTest.php new file mode 100644 index 0000000000..6f8a7ef51a --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Slk/SlkCommentsTest.php @@ -0,0 +1,23 @@ +load($testbook); + $sheet = $spreadsheet->getActiveSheet(); + $comments = $sheet->getComments(); + self::assertCount(2, $comments); + self::assertArrayHasKey('A1', $comments); + self::assertArrayHasKey('B2', $comments); + self::assertSame("Zeratul:\nEn Taro Adun!", $sheet->getComment('A1')->getText()->getPlainText()); + self::assertSame("Arthas:\nFrostmourne Hungers.", $sheet->getComment('B2')->getText()->getPlainText()); + $spreadsheet->disconnectWorksheets(); + } +} diff --git a/tests/data/Reader/Slk/issue.2276.slk b/tests/data/Reader/Slk/issue.2276.slk new file mode 100644 index 0000000000..2fedd073f5 --- /dev/null +++ b/tests/data/Reader/Slk/issue.2276.slk @@ -0,0 +1,10 @@ +ID;PWXL;N;E +P;PGeneral +F;P0;DG0G10;M320 +B;Y3;X1;D0 0 9 0 +C;Y1;X1;AZeratul: :En Taro Adun! +C;Y2;X2;AArthas: :Frostmourne Hungers. +C;Y1;X1;K1 +C;Y1;X2;K2 +C;Y2;X1;K3 +E