phpword中的一行多颜色文本?
有什么方法可以像这样在同一行中书写不同颜色的文本,但会改变整行的颜色 我希望我的台词是这样的:phpword中的一行多颜色文本?,php,phpword,Php,Phpword,有什么方法可以像这样在同一行中书写不同颜色的文本,但会改变整行的颜色 我希望我的台词是这样的: 这是我的密码: $section->addText( 'Headline: ', (array('color'=>'#70AD47')),$fontStyleIndexPara); $section->addText(cleanstring($data[$k]['ArticleTitle']),$fontStyleIndexPara);
这是我的密码:
$section->addText( 'Headline: ', (array('color'=>'#70AD47')),$fontStyleIndexPara);
$section->addText(cleanstring($data[$k]['ArticleTitle']),$fontStyleIndexPara);
`
是的,你可以用这样的东西:
$sentence='Your text in this sentence the two first word will get the stylefont while the rest will get the stylefont2';
$word_arr=explode(' ', $sentence);
$phpWord->addParagraphStyle('p3Style',array('align'=>'center'));
$c = 0;
$textrun = $section->addTextRun(array('align' => 'center'));
for($i = 0; $i < count($word_arr); $i++)
{
$c++;
if($c < 2)
{
$textrun->addText($word_arr[$i].' ', $styleFont);
}
else
{
$textrun->addText($word_arr[$i].' ', $styleFont2);
}
}
$句子=“你的文本在这个句子中,前两个单词将得到stylefont,而其余的将得到stylefont2';
$word_arr=爆炸(“”,$句子);
$phpWord->addParagraphStyle('p3Style',array('align'=>'center');
$c=0;
$textrun=$section->addTextRun(数组('align'=>'center');
对于($i=0;$iaddText($word_arr[$i].',$styleFont);
}
其他的
{
$textrun->addText($word_arr[$i].',$styleFont2);
}
}
不要用addText()将单个文本部分直接写入节中,而是用addTextRun()将其括起来
通过使用addTextRun()可以防止换行
示例代码:
$TextRun = $section->addTextRun();
$TextRun->addText( 'Headline: ', array('color'=>'70AD47'));
$TextRun->addText(cleanstring($data[$k]['ArticleTitle']));
#不用于颜色