【发布时间】:2016-11-25 11:36:22
【问题描述】:
我想要一个包含 3 行文本的页脚,在第 2 行和第 3 行之间有一个垂直空格(如空白行)。 因为第 3 行包含粗体和普通文本,所以我必须将其实现为 textrun。 但是第 1 行和第 2 行之间应该有一个换行符,所以我对这两行都使用了 addText。
很遗憾,页脚内容的显示顺序如下:
-
文本运行
页脚文本1
页脚文本2
textrun 首先被处理并出现在其他行之上!
我怎样才能得到正确的订单?
我的页脚代码是:
// create footer
$footer = $section->addFooter();
// textrun declaration removed from here
// create footer content
$footerText1 = "Blah blah blah.";
$footerText2 = "Ipsum loret Ipsum loret Ipsum loret.";
// define font styles
$smallFontStyleName = 'smallText';
$phpWord->addFontStyle($smallFontStyleName, array(
'name' => 'Helvetica',
'size' => 8,
));
$boldSmallFontStyleName = 'BoldSmallText';
$phpWord->addFontStyle($boldSmallFontStyleName, array(
'bold' => true,
'name' => 'Helvetica',
'size' => 8,
));
// define paragraph spacing styles
$phpWord->addParagraphStyle('line1FooterStyle', array( 'spaceAfter'=>20));
$phpWord->addParagraphStyle('line2FooterStyle', array( 'spaceAfter'=>380));
// add content
$footer->addText($footerText1,
array('name' => 'Helvetica', 'size' => 8),
array('space' => array('after' => 20))
);
$footer->addText($footerText2,
array('name' => 'Helvetica', 'size' => 8),
array('space' => array('after' => 380))
);
// textrun 重定位到这里
$textrun = $footer->addTextRun();
$textrun->addText('T', $boldSmallFontStyleName);
$textrun->addText(' ++353 1 555 0001 ', $smallFontStyleName);
$textrun->addText('E', $boldSmallFontStyleName);
$textrun->addText(' abc.def@ghk.ie ', $smallFontStyleName);
$textrun->addText('W', $boldSmallFontStyleName);
$textrun->addText(' abcd.ie/wxz', $smallFontStyleName);
【问题讨论】:
-
一种选择可能是放弃使用
addFooter()并将整个页脚实现为textrun。 -
但是我需要在第 1 行和第 2 行之后换行。我会尝试多个文本运行,看看效果如何。
-
好的,我看到了问题并修复了它。我在 $footer->addText 行之前声明了 textrun。这意味着首先错误地插入了 textrun 代码。哦!