2016-08-31 2 views
2

Ich benutze PHPWord, um einen Bericht zu generieren, aber ich finde keine Möglichkeit, die Tabellenüberschriften auf jeder Seite zu behalten. Das Problem ist, dass ich den Zellen keinen Stil verleihen kann und zwischen der Kopfzeile und der Haupttabelle etwas Platz ist.Tabellenkürzel jeder Seite Word PHPWord

Ich versuche, aber ich denke, dass nicht die beste Lösung ist:

<?php 
require_once 'PHPWord.php'; 

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

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

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

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

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

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

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

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


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

Meine Frage ist, gibt es eine bessere Möglichkeit, die Tabellenköpfe auf jeder Seite als diese zu halten?

Ergebnis: enter image description here

Antwort

1

In PhpWord 0.13.0 Sie eine Tabelle Kopfzeile definieren, die tblHeader auf jede neue Seite mit Zeilenparametern wiederholt wird:

// your header row addition 
$table->addRow(900, array('tblHeader' => true)); 
+0

Sie nicht vergessen zu erwähnen, dass, wenn Ihr Header enthält mehr als eine Zeile, Sie müssen das Array zu allen hinzufügen. – Chococroc