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
最新推荐文章于 2023-06-01 18:08:08 发布
本文详细介绍了如何使用PHPWord库创建一个包含多种样式的Word文档,包括添加文本、链接、颜色和字体效果。通过定义不同的段落、字体和链接样式,可以轻松地将文本元素组织成具有专业外观的文档。
1400

被折叠的 条评论
为什么被折叠?



