Table Headers each page Word PHPWord
<p>I am using PHPWord to generate a report, but I don't find a way to keep the table headers in each page. The problem is that I can´t to give style to the cells and there is some space between the header and the main table.</p>

<p>I try this, but I think that is not the best solution:</p>

<pre><code>&lt;?php
require_once 'PHPWord.php';

// New Word Document
$PHPWord = new PHPWord();

// New portrait section
$section = $PHPWord-&gt;createSection();

// Define table style arrays
$styleTable = array('borderSize'=&gt;6, 'borderColor'=&gt;'006699', 'cellMargin'=&gt;80);
$styleFirstRow = array('borderBottomSize'=&gt;18, 'borderBottomColor'=&gt;'0000FF', 'bgColor'=&gt;'66BBFF');

// Define cell style arrays
$styleCell = array('valign'=&gt;'center');
$styleCellBTLR = array('valign'=&gt;'center', 'textDirection'=&gt;PHPWord_Style_Cell::TEXT_DIR_BTLR);

// Define font style for first row
$fontStyle = array('bold'=&gt;true, 'align'=&gt;'center');

// Add table style
$PHPWord-&gt;addTableStyle('myOwnTableStyle', $styleTable, $styleFirstRow);
$header = $section-&gt;createHeader();
$table = $header-&gt;addTable();
$table-&gt;addRow(900);
$table-&gt;addCell(2000,$styleCell)-&gt;addText('Row1',$fontStyle);
$table-&gt;addCell(2000,$styleCell)-&gt;addText('Row2',$fontStyle);
$table-&gt;addCell(2000,$styleCell)-&gt;addText('Row3',$fontStyle);
$table-&gt;addCell(2000,$styleCell)-&gt;addText('Row4',$fontStyle);
$table-&gt;addCell(500,$styleCell)-&gt;addText('Row5',$fontStyle);
// Add table
$table = $section-&gt;addTable('myOwnTableStyle');

// Add more rows / cells
for($i = 1; $i &lt;= 1000; $i++) {
    $table-&gt;addRow();
    $table-&gt;addCell(2000)-&gt;addText("Cell $i");
    $table-&gt;addCell(2000)-&gt;addText("Cell $i");
    $table-&gt;addCell(2000)-&gt;addText("Cell $i");
    $table-&gt;addCell(2000)-&gt;addText("Cell $i");

    $text = ($i % 2 == 0) ? 'X' : '';
    $table-&gt;addCell(500)-&gt;addText($text);
}


// Save File
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter-&gt;save('AdvancedTable.docx');
?&gt;
</code></pre>

<p>My question is, is there a better option to keep the table headers in each page than this?</p>

<p>Result:
<a href="https://i.stack.imgur.com/kMFQ3.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kMFQ3.jpg" alt="enter image description here"></a></p>