Search code examples
phpalignmentphpword

PHPWord: align a date field to the right


Using PHPWord, I'm trying to align to the right a date field in word template.

$right = array('align' => 'right');
$objTextRun = $firstSection->addTextRun(array_merge($right, $singleLineHeight));
$firstSection->addField('DATE', array('dateformat' => 'dd/MM/yyyy'), array());

but the date remains aligned to the left, and only the line before is aligned to the right. Need help please.


Solution

  • You are adding your date to the section instead of the textrun (where you have your right alignment rules defined). So with that fixed:

    $right = array('align' => 'right');
    $objTextRun = $firstSection->addTextRun(array_merge($right, $singleLineHeight));
    $objTextRun->addField('DATE', array('dateformat' => 'dd/MM/yyyy'), array());