diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index 245c27d2..52e204fd 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -957,9 +957,10 @@ class Xlsx extends BaseReader // Loop through contents $contentPath = self::xpathNoFalse($commentsFile, 'com:commentList/com:comment'); foreach ($contentPath as $comment) { - $commentModel = $docSheet->getComment((string) $comment['ref']); - if (!empty($comment['authorId'])) { - $commentModel->setAuthor($authors[(int) $comment['authorId']]); + $commentx = $comment->attributes(); + $commentModel = $docSheet->getComment((string) $commentx['ref']); + if (isset($commentx['authorId'])) { + $commentModel->setAuthor($authors[(int) $commentx['authorId']]); } $commentModel->setText($this->parseRichText($comment->children($mainNS)->text)); } diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/CommentTest.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/CommentTest.php new file mode 100644 index 00000000..a80323a5 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/CommentTest.php @@ -0,0 +1,26 @@ +load($filename); + + $sheet = $spreadsheet->getActiveSheet(); + $comment = $sheet->getComment('A1'); + $commentString = (string) $comment; + self::assertStringContainsString('編號長度限制:', $commentString); + self::assertSame('jill.chen', $comment->getAuthor()); + $comment = $sheet->getComment('E1'); + $commentString = (string) $comment; + self::assertStringContainsString('若為宅配物流僅能選「純配送」', $commentString); + self::assertSame('Anderson Chen 陳宗棠', $comment->getAuthor()); + } +} diff --git a/tests/data/Reader/XLSX/issue.2316.xlsx b/tests/data/Reader/XLSX/issue.2316.xlsx new file mode 100644 index 00000000..4356a358 Binary files /dev/null and b/tests/data/Reader/XLSX/issue.2316.xlsx differ