PHPWord/samples/Sample_36_RTL.php

46 lines
1.5 KiB
PHP
Raw Normal View History

<?php
2022-09-16 11:45:45 +02:00
include_once 'Sample_Header.php';
// New Word document
2015-01-01 20:41:42 +04:00
echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
2016-06-04 20:06:37 +04:00
// New section
$section = $phpWord->addSection();
2016-06-04 20:06:37 +04:00
$textrun = $section->addTextRun();
2016-06-04 20:06:37 +04:00
$textrun->addText('This is a Left to Right paragraph.');
2022-09-16 11:45:45 +02:00
$textrun = $section->addTextRun(['alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END]);
$textrun->addText('سلام این یک پاراگراف راست به چپ است', ['rtl' => true]);
2019-01-03 11:33:56 +01:00
$section->addText('Table visually presented as RTL');
2022-09-16 11:45:45 +02:00
$style = ['rtl' => true, 'size' => 12];
$tableStyle = ['borderSize' => 6, 'borderColor' => '000000', 'width' => 5000, 'unit' => \PhpOffice\PhpWord\SimpleType\TblWidth::PERCENT, 'bidiVisual' => true];
2019-01-03 11:33:56 +01:00
$table = $section->addTable($tableStyle);
2022-09-16 11:45:45 +02:00
$cellHCentered = ['alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER];
$cellHEnd = ['alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END];
$cellVCentered = ['valign' => \PhpOffice\PhpWord\Style\Cell::VALIGN_CENTER];
2019-01-03 11:33:56 +01:00
//Vidually bidirectinal table
$table->addRow();
$cell = $table->addCell(500, $cellVCentered);
$textrun = $cell->addTextRun($cellHCentered);
$textrun->addText('ردیف', $style);
$cell = $table->addCell(11000);
$textrun = $cell->addTextRun($cellHEnd);
$textrun->addText('سوالات', $style);
$cell = $table->addCell(500, $cellVCentered);
$textrun = $cell->addTextRun($cellHCentered);
$textrun->addText('بارم', $style);
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
include_once 'Sample_Footer.php';
}