我想知道是否还有左右对齐同一行的一些文字.例如,简历的公司名称与左侧对齐,日期与右侧对齐,在同一条线上.
我试图用文本运行来做这件事,但似乎没有用.我知道我可以使用,\t\t但左侧文本的长度不同,因此选项卡将非常不一致.
这只是一个简单的例子:
$section = $phpWord->addSection();
$textrun = $section->addTextRun();
$textrun->addText("Left Text", array(), array("align" => "left"));
$textrun->addText("Right Text", array(), array("align" => "right"));
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.谢谢.
您可以使用带有单个自定义制表位的段落样式,在右边距右对齐的情况下,在同一行文本上实现不同对齐的效果.
$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");
Run Code Online (Sandbox Code Playgroud)