Files
oleibman b57a549fab More RTL Support for Xlsx/Html Comments
Following up from PR #4006. There is an additional RTL property available. It controls the placement of bidirectional neutral characters (mainly punctuation), as opposed to strong (alphabetic characters) or weak (numeric characters), especially at the beginning or end of a line. The new Comment property textboxDirection will be used for that purpose.

In a discussion in issue #4004 following the implementation of the PR, the comment was mixed RTL and LTR, and this led to some formatting problems. The user was able to overcome these with the timely insertion of Unicode directional control characters, but it would be preferable to have it happen automatically, which this change will permit. However, the use of these control characters cannot be entirely done away with. In the new test case, if one of the all-English lines ended with, say, a colon, it would not display correctly; LRM (left-to-right mark) after the colon would be needed. Likewise, one or two of the comment lines with mixed RTL and LTR (discussed in the issue) is not formatted correctly, and might require LRO/PDF or equivalent.
2024-06-06 16:55:27 -07:00

111 lines
4.3 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Comment;
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->getCell('A3')->setValue('A3');
$sheet->getCell('A4')->setValue('A4');
$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();
}
public function testIssue4004td(): void
{
$type = 'Xlsx';
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setRightToLeft(true);
$sheet->getCell('A1')->setValue('ברקוד');
$comment = $sheet->getComment('A1');
$comment->setTextboxDirection(Comment::TEXTBOX_DIRECTION_RTL);
$comment->setAlignment(Alignment::HORIZONTAL_RIGHT);
$text = <<<EOF
Report : ProductsExcel
סטטוס הגדרות בזמן הרצת הדו"ח
2024-06-04 21:07:04
תאריך התחלה :
תאריך סיום :
berber@berber.co.il
הצגת ברקוד מקוצר = 0
הצגת חנויות אינטרנט בתוצאות = 1
הצגת מחיר ליחידת מידה = 0
הצגת כל רשומות המחיר לתאריך = 0
רשומות עם מחיר בכל הרשתות = 0
% נפיצות מינימלית = 0
נפיצות מינימלית= 0
% נפיצות מקסימלית = 0
נפיצות מקסימלית= 0
פער אחוזי = 0
התעלמות מכלל המבצעים = 0
התעלמות ממבצעי אשראי = 0
התעלמות ממבצעי מועדון = 0
התעלמות ממבצעים המותנים בסכום מעל 100 ₪. = 0
התעלמות ממבצעים המותנים בקניה של 3 מוצרים ומעלה. = 0
ניתוח מבצעים
============
הצגת כל המבצעים = 0
מבצעי מועדון = 0
מבצעי אשראי = 0
מבצעי ארנק = 0
מחיר מוזל = 0
X יחידות ב-Y ₪ = 0
השני ב = 0
X+Y מתנה = 0
אחוז הנחה הפעלה = 0
אחוז הנחה מספר = 0
מוצרים חסרים - הגבלת חודשים - כמות= 0
EOF;
$comment->getText()->createTextRun($text);
$comment->setWidth('300pt');
$comment->setHeight('550pt');
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $type);
$spreadsheet->disconnectWorksheets();
self::assertCount(1, $reloadedSpreadsheet->getAllSheets());
$rsheet = $reloadedSpreadsheet->getActiveSheet();
$comment1 = $rsheet->getComment('A1');
self::assertSame($text, $comment1->getText()->getPlainText());
$comment->setTextboxDirection(Comment::TEXTBOX_DIRECTION_RTL);
self::assertSame('right', $comment1->getAlignment());
self::assertSame('rtl', $comment1->getTextboxDirection());
$reloadedSpreadsheet->disconnectWorksheets();
}
}