我正在使用 PHPWord 生成报告,但我找不到在每个页面中保留表标题的方法。问题是我可以\xc2\xb4t 为单元格提供样式,并且标题和主表之间有一些空间。
\n\n我尝试这样做,但我认为这不是最好的解决方案:
\n\n<?php\nrequire_once \'PHPWord.php\';\n\n// New Word Document\n$PHPWord = new PHPWord();\n\n// New portrait section\n$section = $PHPWord->createSection();\n\n// Define table style arrays\n$styleTable = array(\'borderSize\'=>6, \'borderColor\'=>\'006699\', \'cellMargin\'=>80);\n$styleFirstRow = array(\'borderBottomSize\'=>18, \'borderBottomColor\'=>\'0000FF\', \'bgColor\'=>\'66BBFF\');\n\n// Define cell style arrays\n$styleCell = array(\'valign\'=>\'center\');\n$styleCellBTLR = array(\'valign\'=>\'center\', \'textDirection\'=>PHPWord_Style_Cell::TEXT_DIR_BTLR);\n\n// Define font style for first row\n$fontStyle = array(\'bold\'=>true, \'align\'=>\'center\');\n\n// Add table style\n$PHPWord->addTableStyle(\'myOwnTableStyle\', $styleTable, $styleFirstRow);\n$header = $section->createHeader();\n$table = $header->addTable();\n$table->addRow(900);\n$table->addCell(2000,$styleCell)->addText(\'Row1\',$fontStyle);\n$table->addCell(2000,$styleCell)->addText(\'Row2\',$fontStyle);\n$table->addCell(2000,$styleCell)->addText(\'Row3\',$fontStyle);\n$table->addCell(2000,$styleCell)->addText(\'Row4\',$fontStyle);\n$table->addCell(500,$styleCell)->addText(\'Row5\',$fontStyle);\n// Add table\n$table = $section->addTable(\'myOwnTableStyle\');\n\n// Add more rows / cells\nfor($i = 1; $i <= 1000; $i++) {\n $table->addRow();\n $table->addCell(2000)->addText("Cell $i");\n $table->addCell(2000)->addText("Cell $i");\n $table->addCell(2000)->addText("Cell $i");\n $table->addCell(2000)->addText("Cell $i");\n\n $text = ($i % 2 == 0) ? \'X\' : \'\';\n $table->addCell(500)->addText($text);\n}\n\n\n// Save File\n$objWriter = PHPWord_IOFactory::createWriter($PHPWord, \'Word2007\');\n$objWriter->save(\'AdvancedTable.docx\');\n?>\nRun Code Online (Sandbox Code Playgroud)\n\n我的问题是,是否有比这更好的选择来将表标题保留在每个页面中?
\n\n\n在 PhpWord 0.13.0 中,您可以使用 row 参数定义在每个新页面上重复的表标题行tblHeader:
// your header row addition
$table->addRow(900, array('tblHeader' => true));
Run Code Online (Sandbox Code Playgroud)