2016-11-21 55 views
1

我可以在section中使用textrun替換文檔正文中的純文本和粗體文本。phpWord footer中的替代粗體和常規文本

$textrun->addText(' Short address here '); 
$textrun->addText(' T ', $boldFontStyleName); 
$textrun->addText(' ++353 1 5552999. '); 

但我不能在我需要它的地方,在FOOTER中獲得相同的效果。文本與$footer->addText一起添加,不允許內聯添加新文本。

我試過了解我所知道的一切,包括連接並將$textrun->addText輸出分配給一個新的$variable,我只通過$footer->addText($variable)向頁腳添加一次;沒有運氣。

我現在的代碼如下,如果有人可以調整它的工作,我會很感激。或者,它只是在phpWord的頁腳不支持這種格式的水平?

// footer 
$footer = $section->addFooter(); 

// define bold style 
$boldFontStyleName = 'BoldText'; 
$phpWord->addFontStyle($boldFontStyleName, array('bold' => true)); 

// add text 
$footer->addText(' Short address here '); 
$footer->addText(' T ', $boldFontStyleName); 
$footer->addText(' ++353 1 5552999. '); 

回答

2

您可以在頁腳,你在節將(至少在phpword版本0.13.0)同樣使用textrun:

// footer 
$footer = $section->addFooter(); 
$textrun = $footer->addTextRun(); 

// define bold style 
$boldFontStyleName = 'BoldText'; 
$phpWord->addFontStyle($boldFontStyleName, array('bold' => true)); 

// add text 
$textrun->addText(' Short address here '); 
$textrun->addText(' T ', $boldFontStyleName); 
$textrun->addText(' ++353 1 5552999. '); 
+0

謝謝!我以爲我曾嘗試過,但我必須留下一些東西。這是你救了我兩次! – Benjamin

相關問題