doucuyu2259 2016-08-31 05:27
浏览 21

表标题每页Word PHPWord

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.

I try this, but I think that is not the best solution:

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

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

Result: enter image description here

  • 写回答

1条回答 默认 最新

  • drny60365 2016-09-02 06:26
    关注

    In PhpWord 0.13.0 you can define a table header row that is repeated on every new page with row parameter tblHeader:

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

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统