mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-26 18:11:13 +00:00
455f1129bf
Fix #4004. RTL text can be included in a comment, and will display correctly, but the comment as a whole will be left-aligned. There already exists an `alignment` property for Comment, but it is unused. This PR will allow that property to be set, and to be read from and written to an Xlsx spreadsheet when possible. The Xml tags that govern this property are found, unusually, in a drawing Vml file. The important property is `x:TextHAlign`, which can be set to Left, Right, Center, Justified, or Distributed. There are other tags which seemed like they were relevant to this problem, but I don't think they actually matter: ```xml <v:textbox style='mso-direction-alt:auto'> <div style='text-align:right;direction:rtl'></div> </v:textbox> ```
38 lines
1.3 KiB
PHP
38 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
|
|
|
|
class CommentAlignmentTest extends AbstractFunctional
|
|
{
|
|
public function testIssue4004(): void
|
|
{
|
|
$type = 'Xlsx';
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$sheet->getComment('A3')->getText()->createText('Comment');
|
|
$sheet->getComment('A4')->getText()->createText('שלום');
|
|
$sheet->getComment('A4')->setAlignment(Alignment::HORIZONTAL_RIGHT);
|
|
|
|
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $type);
|
|
$spreadsheet->disconnectWorksheets();
|
|
|
|
self::assertCount(1, $reloadedSpreadsheet->getAllSheets());
|
|
|
|
$rsheet = $reloadedSpreadsheet->getActiveSheet();
|
|
$comment1 = $rsheet->getComment('A3');
|
|
self::assertSame('Comment', $comment1->getText()->getPlainText());
|
|
self::assertSame('general', $comment1->getAlignment());
|
|
$comment2 = $rsheet->getComment('A4');
|
|
self::assertSame('שלום', $comment2->getText()->getPlainText());
|
|
self::assertSame('Right', $comment2->getAlignment());
|
|
|
|
$reloadedSpreadsheet->disconnectWorksheets();
|
|
}
|
|
}
|