我在这里尝试了另一篇文章,重新应用标题样式,但该代码也没有任何作用。在这里,我的 PHPWord 构建了使用"Open Sans"成功显示硬编码变量的部分;但是当我更改为在表中显示信息时,它始终默认为"Arial"10。请看看您是否可以帮助说明为什么会发生这种情况,谢谢!注意 - 要获得输出以均匀地显示单元格之间的线条,我正在尝试文本中的其他样式。即使我将$BodyFontStyle应用于每个addCell,addText和addRow,仍然 - 仅Arial。我需要在"Open Sans"10 中显示该表。请帮忙——
$firstRowStyle = array('name' => 'Open Sans', 'size' => 10, 'valign' => 'bottom');
$BodyFontStyle = array('name'=>'Open Sans', 'bold'=>false, 'size'=>14);
$table_cell_style = array('valign' => 'top');
$lineStyle = array('name' => 'Open Sans', 'size' => 10, 'valign' => 'bottom');
//from above, this flag is not set, or set:
if ($signatory_found == 1) { //from mySQL query looking for Signatory.
$PHPWord->addTableStyle('BodyFontStyle', array('name'=>'Open Sans', 'bold'=>false, 'size'=>14));
$table = $section->addTable('BodyFontStyle');
//tried this, to no avail:
//$PHPWord->addTableStyle($BodyFontStyle);
//$table = $section->addTable($BodyFontStyle);
for ($i=0; $i <= $counter; $i++) {
$table->addRow();
$table->addCell(1600, $firstRowStyle)->addText("BY:_____________________________________________________");
$table->addCell(200, $firstRowStyle)->addText('');
$table->addCell(1600, $firstRowStyle)->addText(" ____________________________");
$table->addRow();
$full_name_title = " " . $signatory_results[$i]['first'] . " " . $signatory_results[$i]['last'] . ", " . $signatory_results[$i]['title'];
$table->addCell(1600, $table_cell_style)->addText("{$full_name_title}");
$table->addCell(200, $firstRowStyle)->addText(''); //space between name, and date.
$table->addCell(1600, $table_cell_style)->addText(" Date");
}
} else { //else signatory flag was not set to 1, so no records found.
$table = $section->addTable('BodyFontStyle');
$PHPWord->addTableStyle('BodyFontStyle', array('name'=>'Open Sans', 'bold'=>false, 'size'=>14));
$table->addRow();
$table->addCell(1600, $firstRowStyle)->addText("BY:_________________________________");
$table->addCell(200, $firstRowStyle)->addText('');
$table->addCell(1600, $firstRowStyle)->addText("_______________________");
$table->addRow();
$table->addCell(1600, $firstRowStyle)->addText(" Signature");
$table->addCell(200, $firstRowStyle)->addText('');
$table->addCell(1600, $firstRowStyle)->addText(" Date");
$table->addRow();
$table->addCell(1600, $lineStyle)->addText(" ____________________________________", array(), array('cellMarginLeft' => 6));
$table->addCell(200, $firstRowStyle)->addText('');
$table->addCell(1600, $firstRowStyle)->addText("_______________________");
$table->addRow();
$table->addCell(1600, $table_cell_style)->addText(" Print Name");
$table->addCell(200, $firstRowStyle)->addText('');
$table->addCell(1600, $table_cell_style)->addText(" Print Title");
}
// Hack - Martin/Pitt has a / in the LP Short name which messes up the filename/path
$LPShort = str_replace("/", "-", $LPShort);
$LPShort = str_replace(" ", "-", $LPShort);
$objWriter = PhpOfficePhpWordIOFactory::createWriter( $PHPWord, 'Word2007' );
$filelocation = '/var/www/company/contracts/tmp';
$filename = 'Sig_'.$LPShort."_".date('YmdHis',time()).'.docx';
$FullName = $filelocation.'/'.$filename;
//echo $FullName;
$objWriter->save($FullName);
echo $filename;
exit;
修复- 我不会再次发布所有代码,但此命令将显示解决方案。关键是将定义的样式与 addCell 命令内联,放在文本之后的末尾。请注意,在上面,我只是有带有文本的addCell,但之后没有样式。我将发布一个前后命令来解释:
/*BEFORE* $table->addCell(1600, $table_cell_style)->addText("{$full_name_title}");
/*AFTER*/ $table->addCell(1600, $table_cell_style)->addText("{$full_name_title}", $BodyFontStyle);