我尝试使用 PHPWord 创建word文件。我设置了一些字体样式和段落样式。即使没有给出textbreaks,我在line1和line2之间得到6行空格。有什么建议吗?
这是我的代码
$this->word->addFontStyle('titleStyle', array('bold' => true, 'size' => 16, 'name'=>'Calibri'));
$this->word->addFontStyle('lineStyle', array('align'=>'left','size' => 10, 'name'=>'Calibri'));
$this->word->addParagraphStyle('pStyle', array('align' => 'center', 'spaceBefore' => 0, 'spaceAfter' => 0, 'spacing' => 0));
$section = $this->word->createSection(array('breakType'=>'continuous'));
// Simple text
$section->addText('Text Document','titleStyle','pStyle');
$section->addText('Line1 : ','lineStyle');
$section->addText('Line2 : ','lineStyle');
$section->addText('Line3 : ','lineStyle');
$section->addText('Line4 : ','lineStyle');
$filename='NewDoc.docx'; //save our document as this file name
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); //mime type
header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
header('Cache-Control: max-age=0'); //no cache
$objWriter = PHPWord_IOFactory::createWriter($this->word, 'Word2007');
$objWriter->save('php://output');
任何帮助将不胜感激。
答案 0 :(得分:0)
您定义的段落样式不适用于任何添加的文本。
如果要将已定义的段落样式应用于添加的文本,则需要将名称(或定义)添加为参数:
$section->addText('Line 1 : '.$line1,'lineStyle', 'pStyle');
或者如果您希望创建将在任何地方自动使用的全局段落样式:
$phpWord->setDefaultParagraphStyle(array('align'=>'left','size' => 10, 'name'=>'Calibri'));