Forum


Replies: 6   Views: 3954
Add different header to each section
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by khosro  · 07-03-2016 - 07:35

Hi,

I wan to add different header to each section.In word you can add different header to each section if "Link to previouse" is disbled.

I wrote the following code in order to create different header for each section,but it only insert header for last section :

 

for ($i = 0; $i < 5; $i++) {

    if ($i !== 0) {
        $docx->addSection('nextPage', 'A4');
    }

    $textOptions = array('fontSize' => 13, 'b' => 'on', 'color' => '567899',);

    $widthTableCols = array(700);

    $paramsTable = array('border' => 'nil', 'columnWidths' => $widthTableCols);

    $defaultHeader = 'defaultHeader' . $i;
    $default = 'default' . $i;

    $headerText = new WordFragment($docx, $defaultHeader);
    $headerText->addText('PHPDocX Header Title' . $i, $textOptions);

    $valuesTable = array(array(array('value' => $headerText, 'vAlign' => 'center')));

    $headerTable = new WordFragment($docx, $defaultHeader);
    $headerTable->addTable($valuesTable, $paramsTable);

    $docx->addHeader(array($default => $headerTable));
 
    $docx->addText('This document has a header'.$i);
}

 

Any idea to add different header to each section?