mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-07 08:37:05 +00:00
8557ccb72a
Fix #4081. Ods Reader was not reading entire contents of comment. On further inspection, Ods Writer also was not handling comments completely correctly. Ods comments are recorded as `text:p` children of `office:annotation` elements. A newline is inserted between successive `text:p` elements. The `text:p` element itself can have as descendants (at least): - raw text - `text:span` elements - `text:line-break` elements, which also causes the insertion of a newline Ods Writer is changed to use a single `text:p` with multiple span/linebreak elements. Ods Reader is changed to process in their entirety either that form, or multiple `text:p` elements. Styling of the individual elements of the comment is permitted in Ods. That has not been supported till now by PhpSpreadsheet, and this PR will not address that situation - Ods Reader hast little style support, and this would hardly be the most urgent case where it is missing.
42 lines
1.5 KiB
PHP
42 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Ods;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
|
|
|
|
class MultiLineCommentTest extends AbstractFunctional
|
|
{
|
|
public function testMultipleParagraphs(): void
|
|
{
|
|
$filename = 'tests/data/Reader/Ods/issue.4081.ods';
|
|
$reader = new Ods();
|
|
$spreadsheet = $reader->load($filename);
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
self::assertSame("First line.\n\nSecond line.", $sheet->getComment('A1')->getText()->getPlainText());
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
|
|
public function testOneParagraphMultipleSpans(): void
|
|
{
|
|
$spreadsheetOld = new Spreadsheet();
|
|
$sheetOld = $spreadsheetOld->getActiveSheet();
|
|
$sheetOld->getCell('A1')->setValue('Hello');
|
|
$text = $sheetOld->getComment('A1')->getText();
|
|
$text->createText('First');
|
|
$text->createText(' line.');
|
|
$text->createText("\n");
|
|
$text->createText("\n");
|
|
$text->createText("Second line.\nThird line.");
|
|
$spreadsheet = $this->writeAndReload($spreadsheetOld, 'Ods');
|
|
$spreadsheetOld->disconnectWorksheets();
|
|
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
self::assertSame("First line.\n\nSecond line.\nThird line.", $sheet->getComment('A1')->getText()->getPlainText());
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
}
|