I've been going through the samples folder as well as looking on the website but somehow I'm missing how to align cell contents to the right. I see a 'vAlign' option but don't know how to set the horizontal align.
I've been going through the samples folder as well as looking on the website but somehow I'm missing how to align cell contents to the right. I see a 'vAlign' option but don't know how to set the horizontal align.
Okay, I searched from Google and found this post. Looks like I have to create a text fragment with textAlign = 'right' and then set that as the cell's value.
https://www.phpdocx.com/en/forum/default/topic/658
Hello,
In a table, vertical align is a cell style, but horizontal align is a paragraph style. You can set a custom horizontal align creating a WordFragment and adding it to the table.
For example:
$docx = new CreateDocx();
$textFragmentLeft = new WordFragment($docx, 'document');
$textFragmentLeft->addText('Default alignment');
$textFragmentCenter = new WordFragment($docx, 'document');
$textFragmentCenter->addText('Center alignment', ['textAlign' => 'center']);
$textFragmentRight = new WordFragment($docx, 'document');
$textFragmentRight->addText('Right alignment', ['textAlign' => 'right']);
$valuesTable = array(
array(
$textFragmentLeft,
$textFragmentCenter,
$textFragmentRight,
),
array(
'Other cell 1',
'Other cell 2',
'Other cell 3',
),
);
$docx->addTable($valuesTable);
$docx->createDocx('output');
You can also apply other styles (such as bold, font size...) to the WordFragments and also add more than one content to the same WordFragment if needed (https://www.phpdocx.com/documentation/practical/wordfragments-and-wordml).
In the package you can find a more complex sample that creates a table with WordFragments in the following path: examples/Contents/addTable/sample_4.php
Regards.