require_once 'PHPWord.php';
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
//添加样式定义
$PHPWord->addParagraphStyle('pStyle',array('spacing'=>100));
$PHPWord->addFontStyle('BoldText',array('bold'=>true));
$PHPWord->addFontStyle('ColorredText',array('color'=>'FF8080'));
$PHPWord->addLinkStyle('NLink',array('color'=>'0000ff','underline'=>PHPWord_Style_Font::UNDERLINE_SINGLE));
//添加文本元素
$textrun = $section->createTextRun('pStyle');
$textrun->addText('Each textrun can contain native text or link elements.');
$textrun->addText('No break is placed after adding an element.','BoldText');
$textrun->addText('All elements are placed inside a paragraph with the optionally given p-Style','ColorredText');
$textrun->addText('The best search engine:');
$textrun->addLink('http://www.baidu.com',null.'NLink');
$textrun->addText('Also not bad:');
$textrun->addLink('www.soso.com',null.'NLink');
//保存文件
$objWriter = PHPWord_IOFactory::createWriter($PHPWord,'Word2007');
$objWriter->save('TextRun.docx');
【PHPWord】TextRun
最新推荐文章于 2025-06-06 09:01:05 发布