使用 PHPWord 时,我可以在调用 addListItem 时格式化内联文本吗? [英] When using PHPWord can I format inline text when calling addListItem?

查看:76
本文介绍了使用 PHPWord 时,我可以在调用 addListItem 时格式化内联文本吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PHPWord (https://github.com/PHPOffice/PHPWord/tree/开发) 以生成出现在 Word 文档中的许多项目符号项.我依靠 addListItem() 将项目符号项添加到文档中,这工作得很好.

I'm using PHPWord (https://github.com/PHPOffice/PHPWord/tree/develop) to generate a number of bulleted items appearing within a Word document. I am relying on addListItem() to add the bullet items to the document and that is working just fine.

我遇到的唯一问题是我需要格式化出现在项目符号项中的一些文本,首先出现粗体字,然后出现非粗体文本;都在同一行内.

The only problem I'm having is that I also need format some of the text appearing in the bulleted item with a bold word appearing first followed by non-bold text appearing afterwards; all within the same line.

例如:

  • 粗体字:在一行中显示有关粗体字的更多信息
  • bold word: more information about the bolded word all in one line

我不知道使用 PHPWord 是否可行.我知道我可以通过 addTextRun() 创建一个 textRun 对象来创建我想要的格式,但是当我这样做时,它不会作为项目符号添加到列表中.

I can't figure out if that's a possibility using PHPWord. I know that I can create a textRun object via addTextRun() to create the formatting I want, but when I do that it's not added as a bullet in the list.

有没有办法两全其美?我是否可以不仅获得 textRun 对象的好处,还可以让它显示为项目符号?

Is there a way to get the best of both worlds? Can I not only get the benefit of a textRun object and also have it appear as a bullet?

推荐答案

是的,您正在寻找的是 listItemRun.直接来自示例 https://github.com/PHPOffice/PHPWord/blob/develop/samples/Sample_14_ListItem.php

yep, the thing you are searching for is the listItemRun. Directly from the samples https://github.com/PHPOffice/PHPWord/blob/develop/samples/Sample_14_ListItem.php

$section->addText(htmlspecialchars('List with inline formatting.', ENT_COMPAT, 'UTF-8'));
$listItemRun = $section->addListItemRun();
$listItemRun->addText(htmlspecialchars('List item 1', ENT_COMPAT, 'UTF-8'));
$listItemRun->addText(htmlspecialchars(' in bold', ENT_COMPAT, 'UTF-8'), array('bold' => true));
$listItemRun = $section->addListItemRun();
$listItemRun->addText(htmlspecialchars('List item 2', ENT_COMPAT, 'UTF-8'));
$listItemRun->addText(htmlspecialchars(' in italic', ENT_COMPAT, 'UTF-8'), array('italic' => true));

这篇关于使用 PHPWord 时,我可以在调用 addListItem 时格式化内联文本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆