Table cell - horizontal align?

Oct 27, 2010 at 5:54 PM
In a section, the code below makes the font bold and 'horizontally aligns' the text in the center of the section.

$fontStyle = array ('bold' => true);
$paraStyle = array ('align' => 'center');
$section->addText( 'Hello World', $fontStyle, $paraStyle );

But in a table, the code below makes the font bold, 'vertically aligns' the text in the center of the cell, but does not 'horizontally align' the text in the center of the cell.

$table = $section->addTable();
$table->addRow();

$cellStyle = array ('valign' => 'center');

$fontStyle = array ('bold' => true);
$paraStyle = array ('align' => 'center');

$table->addCell(2000, $cellStyle)->addText('Hello World', $fontStyle, $paraStyle );

What is the right way to horizontally align the contents of a table cell?
Oct 27, 2010 at 7:07 PM
Edited Oct 27, 2010 at 7:08 PM

Oh, I see this is a known bug in PHPWord/Section/Table/Cell.php addText function line 110.

http://phpword.codeplex.com/Thread/View.aspx?ThreadId=222575

Dec 18, 2013 at 8:04 AM
I was able to center the contents of my table cells like this:
$center = array('spaceAfter' => 0, 'align' => 'center');

$table_block_format = array(    'borderSize'        =>  7,
                                'cellMarginTop'     =>  0,
                                'cellMarginLeft'    =>  100,
                                'valign'            =>  'center',
                                                                );

$cellTextStyleBig = array(      'bold'  =>  false, 
                                'size'  =>  22, 
                                'name'  =>  'Calibri'
                                                        );

$cellTextStyleBigBold = array(  'bold'  =>  true, 
                                'size'  =>  22, 
                                'name'  =>  'Calibri'   
                                                        );      

$PHPWord->addTableStyle('myTable', $table_block_format, array('align' => 'center'));

$table = $section->addTable('myTable');
$table->addRow();
$table->addCell(1460)->addText('Size:', $cellTextStyleBigBold, $center);
$table->addCell(3560)->addText('Text Is Centered', $cellTextStyleBig, $center);