PHPWORD页脚文本对齐问题

PHPWORD页脚文本对齐问题,php,phpword,Php,Phpword,我正在使用phpword生成word文件。我的页脚有问题。在页脚,我有页码和一个文本机密文件。页码必须左对齐,机密文件必须右对齐。我尝试了下面的脚本,但文本和页码都只向左对齐 $phpword_object = new PHPWord(); $section = $phpword_object->createSection(); $footer = $section->createFooter(); $footer->addPreserveText('Page {PAGE}

我正在使用phpword生成word文件。我的页脚有问题。在页脚,我有页码和一个文本机密文件。页码必须左对齐,机密文件必须右对齐。我尝试了下面的脚本,但文本和页码都只向左对齐

$phpword_object = new PHPWord();
$section = $phpword_object->createSection();

$footer = $section->createFooter();
$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.',     
array(
    'align' => 'end',
    'positioning' => 'absolute'
));

$text = 'Confidential Document';

$footer->addPreserveText( $text,
    array(
        'align' => 'start',
        'positioning' => 'absolute'
    ));

就我个人而言,我会用一个简单的右对齐选项卡来实现这一点。它更容易理解,无论是以代码形式还是在Word中打开docx文件之后

因此,假设你有一个两边都有2.5厘米边距的A4页面,这会给你一个16厘米宽的区域,所以把标签放在16厘米处,类似这样的东西(这个代码有效-我刚刚尝试过):


要实现此对齐问题,可以使用带有行和单元格的表格以单行左右对齐方式显示文本和页码。 为了在左对齐上显示文本,在右对齐上显示页码,我应用了这个解决方案,它适合我

$section = $phpWord->addSection();
$footer = $section->addFooter();
$table = $section->addTable();
$table->addRow();

$cell = $table->addCell(4500);
$textrun = $cell->addTextRun();
$textrun->addText('left text', array('size' => 11), array('align'=>'left'));
$table->addCell(4500)->addPreserveText('{PAGE}', array('size' => 11), array('align'=>'right'));

我假设你希望两段文字在同一行,对吗?
$section = $phpWord->addSection();
$footer = $section->addFooter();
$table = $section->addTable();
$table->addRow();

$cell = $table->addCell(4500);
$textrun = $cell->addTextRun();
$textrun->addText('left text', array('size' => 11), array('align'=>'left'));
$table->addCell(4500)->addPreserveText('{PAGE}', array('size' => 11), array('align'=>'right'));