This project is read-only.

Text alignment in a cell included in a header or footer

Aug 5, 2010 at 2:12 PM


I have created aheader with cell and images and text inside. Alignement for images works perfeclty well but when I tried to center the text "HERE IS MY TITLE" inside the cell but the text stay on the left.

I am doing something wrong in my code ? I have considered using cellMarginLeft but it would be applied on all the table.

$header_first_page = $section_first_page->createHeader();
$table = $header_first_page->addTable();
$table->addCell(3000,array('valign'=>'bottom'))->addImage('images/ece logo.jpg', array('width'=>76, 'height'=>32, 'align'=>'left'));
$table->addCell(8000,array('valign'=>'center'))->addText("HERE IS MY TITLE",array('bold'=>true),array('align'=>'center'));
$table->addCell(3000)->addImage('images/small_zodiacaerospace.jpeg', array('width'=>147, 'height'=>50, 'align'=>'right'));
$table->addCell(4500)->addText('Reference: '.$ref);
$table->addCell(500)->addText('Issue: '.$issue);

Aug 10, 2010 at 8:43 PM

I had a similar problem when trying to use the properties spaceBefore and spaceAfter. After reviewing the method addText of the cell and compare it to the section I realized that the cell does not have the paragraph style parameters. So I copy the method of the section in the cell and it worked perfectly.


public function addText($text, $style = null) {
$text = utf8_encode($text);
$text = new PHPWord_Section_Text($text, $style);
$this->_elementCollection[] = $text;
return $text;


public function addText($text, $styleFont = null, $styleParagraph = null) 
$givenText = utf8_encode($text); 
$text = new PHPWord_Section_Text($givenText, $styleFont, $styleParagraph); 
$this->_elementCollection[] = $text;
return $text; 

Greetings ...

Aug 11, 2010 at 4:59 PM

Thanks for the bug report.

Will be fixed in a few days.

Apr 3, 2011 at 12:40 AM

Wonderful! It's located in PHPWord/Section/Table/Cell.php.

Jan 31, 2014 at 1:50 PM
Hey i want to add header and footer only on first and second page is it possible ....Plz help