2016-03-02 118 views
2

我想知道是否有左右對齊的文字在同一行上。因此,例如,簡歷的公司名稱將與左側對齊,並且右側的日期位於同一行。在PHPWord中,左右對齊詞

我試圖用文本運行來做到這一點,但似乎沒有工作。我知道我可以使用\t\t,但左邊的文字會有不同的長度,所以選項卡會非常不一致。

這只是一個簡單的例子:

$section = $phpWord->addSection(); 
$textrun = $section->addTextRun(); 
$textrun->addText("Left Text", array(), array("align" => "left")); 
$textrun->addText("Right Text", array(), array("align" => "right")); 

任何幫助,將不勝感激。謝謝。

+0

如何設置MS Word中單個單詞的對齊方式?據我所知,你只能設置段落對齊方式,而不是在行 –

回答

4

您可以使用具有單個自定義製表位的段落樣式,右對齊右邊距,在同一行文本上實現不同對齊效果。

$section = $phpWord->addSection(); 

$section_style = $section->getStyle(); 
$position = 
    $section_style->getPageSizeW() 
    - $section_style->getMarginRight() 
    - $section_style->getMarginLeft(); 
$phpWord->addParagraphStyle("leftRight", array("tabs" => array(
    new \PhpOffice\PhpWord\Style\Tab("right", $position) 
))); 

$section->addText("Left Text\tRight Text", array(), "leftRight"); 
+0

內的文字,謝謝你的回覆。我會馬上測試並回來。 – James

+0

謝謝。工作完美! – James

+0

8500似乎很神奇,所以我決定像這樣計算它: '$ section_style = $ section-> getStyle(); $ position = $ section_style-> getPageSizeW() - $ section_style-> getMarginRight() - $ section_style-> getMarginLeft();' 這樣右邊的文字就會出現在頁面的右邊緣。 – Gherman