我在这里尝试了另一篇关于标题样式未应用的文章,但是该代码也没有执行任何操作。在这里,我的PHPWord构建了使用“ Open Sans”成功显示硬编码变量的部分。但是当我更改为在表中显示信息时,它始终默认为“ Arial” 10。请查看是否可以帮助您说明为什么会发生这种情况,谢谢!注意-为了使输出在单元格之间均匀显示行,我正在尝试文本中的其他样式。即使我将$ BodyFontStyle应用于每个addCell,addText和addRow,仍然-仅Arial。我需要将该表格显示在“无休假” 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 = \PhpOffice\PhpWord\IOFactory::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;
答案 0 :(得分:0)
修复-我不会再次发布所有代码,但是此命令将显示解决方案。关键是在文本之后的末尾,使定义的样式与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);