2016-08-31 2 views
2

보고서를 생성하기 위해 PHPWord를 사용하고 있지만 각 페이지에 표 머리글을 유지하는 방법을 찾지 못했습니다. 문제는 내가 셀에 스타일을 줄 수없고 헤더와 메인 테이블 사이에 약간의 공간이 있다는 것입니다. 이것보다 각 페이지에 테이블 머리글을 유지하기 위해 더 나은 옵션이 있습니다,표 머리글 각 페이지 Word PHPWord

<?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'); 
?> 

내 질문은 :

나는 이것을 시도,하지만 난 그게 최선의 해결책 아니라고 생각

?

결과 : 당신이 행 매개 변수 tblHeader으로 모든 새 페이지에 반복되는 표 머리글 행을 정의 할 수 있습니다 PhpWord의 0.13.0에서 enter image description here

답변

1

가 :

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

이 경우 언급하는 것을 잊지 마세요 헤더에 둘 이상의 행이 포함 된 경우 해당 배열을 모두에 추가해야합니다. – Chococroc