如何只加粗一段的一部分?

How to bold only a part of a paragraph?

我正在从 Google 表单生成文档,我想格式化文档中的特定文本。

这是我的代码:

//Add first paragraph (greeting)
var para1 = body.appendParagraph('Hi '+ email +', thank you for signing our 
                   Laptop Policy. Here\'s a copy for your records.\n\n');

我得到这个结果:

Hi name@domain.com, thank you for signing our Laptop Policy. Here's a copy for your records.

但我想要这样的结果(电子邮件地址仅以粗体显示):

Hi name@domain.com, thank you for signing our Laptop Policy. Here's a copy for your records.

创建 Text 个对象,您可以在特定的文本运行中单独设置粗体 属性:

var para1 = body.appendParagraph('Hi ');

var emailText = para1.appendText(email);
emailText.setBold(true);

para1.appendText(', thank you for signing our Laptop Policy. Here\'s a copy for your records.\n\n');

如果现有段落中只有文本,您也可以只设置部分样式 (https://developers.google.com/apps-script/reference/document/text#setBold(Integer,Integer,Boolean)):

var text = somePara.editAsText();
text.setBold(5, 15, true);