【发布时间】:2013-07-12 01:34:11
【问题描述】:
我想知道是否有办法将某行中的某些单词加粗。例如,如果我想在一行粗体上每隔三个单词,我会怎么做。我目前正在使用 addText 但这需要整行加粗或不加粗。任何回复将不胜感激。
【问题讨论】:
标签: php ms-word doc bold phpword
我想知道是否有办法将某行中的某些单词加粗。例如,如果我想在一行粗体上每隔三个单词,我会怎么做。我目前正在使用 addText 但这需要整行加粗或不加粗。任何回复将不胜感激。
【问题讨论】:
标签: php ms-word doc bold phpword
您将需要使用 createTextRun() 方法。我已经尝试使用 Examples 文件夹中的 Text.php 文件,这里是与您的问题相关的代码:
$textrun = $section->createTextRun();
$sentence='I am sentence, and every third word will be bold. This is bold.';
$word_arr=explode(' ', $sentence);
$styleFont = array('bold'=>true, 'size'=>16, 'name'=>'Calibri');
$styleFont2 = array('bold'=>false, 'size'=>16, 'name'=>'Calibri');
$c = 0;
for($i = 0; $i < count($word_arr); $i++)
{
$c++;
if($c % 3 == 0)
{
$textrun->addText($word_arr[$i].' ', $styleFont);
}
else
{
$textrun->addText($word_arr[$i].' ', $styleFont2);
}
}
你可以调整它以获得你想要的,但是,基本上,通过使用上述方法,可以在同一行中获得不同的样式。
【讨论】: