您将需要使用createTextRun()方法.我试过Text.php
文件Examples
夹中的文件,这里是与您的问题相关的代码:
$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);
}
}
Run Code Online (Sandbox Code Playgroud)
你可以调整它以获得你想要的东西,但是,基本上,通过使用所提到的方法,可以在同一行中获得不同的样式.