Phpword: Set Table Direction RTL

Created on 2 Jan 2019  路  8Comments  路  Source: PHPOffice/PHPWord

How to set table direction rtl?
it's my code:

        $style = array('rtl' => true,
                       'name' => 'B Mitra',
                       'size' => 12);

        $borderStyle = array('borderSize' => 6,
                            'borderColor' => '000000');

        $table = $section->addTable($borderStyle);
        $cellHCentered = array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER);
        $cellHEnd = array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END);
        $cellVCentered = array('valign' => 'center');
        $i = 0;

        //--------------= Questions Header
        $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);

Most helpful comment

@mmasomi73 code has been merged to develop branch.
You can use it by defining the dependency version as "dev-develop"

All 8 comments

Isn't this what you are trying to produce?

image

No, it's exactly reversed, in rtl table columns arranged right to left; first column in right side and last column in left. One solution is arrange columns reverse, but not correct solution;
2019-01-03_09-59-00

Oh I see, it's not only the text that should be RTL, it's also the column order.
Can you provide a simple document with just that so I can see the generated XML?

I have word 2017 for mac, and I don't seem to have this "table direction" option :-(
But I tried with LibreOffice, where the option is present.
It seems what we need is http://www.datypic.com/sc/ooxml/e-w_bidiVisual-1.html
I'll try to create a pull request for this.

yes, Sure.
Questions (13).docx
this file created with office 2013, and table is rtl.

I have word 2017 for mac, and I don't seem to have this "table direction" option :-(
But I tried with LibreOffice, where the option is present.
It seems what we need is http://www.datypic.com/sc/ooxml/e-w_bidiVisual-1.html
I'll try to create a pull request for this.

Exactly, for rtl table use <w:bidiVisual/>

@mmasomi73 code has been merged to develop branch.
You can use it by defining the dependency version as "dev-develop"

Hi @troosan and @mmasomi73
how about RTL in table of content?

Untitled

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ahmednawazbutt picture ahmednawazbutt  路  3Comments

D0Gmatist picture D0Gmatist  路  4Comments

JFSebastianVillalba picture JFSebastianVillalba  路  3Comments

Joel-James picture Joel-James  路  3Comments

taophp picture taophp  路  3Comments