Google apps script 如何使用google脚本替换字体权重?

Google apps script 如何使用google脚本替换字体权重?,google-apps-script,google-docs,Google Apps Script,Google Docs,您好,我尝试在我的谷歌文档中检测特定的字符串,并将其设置为“粗体”。 我试过这个: function bold() { var body = DocumentApp.getActiveDocument().getBody(); var foundElement = body.findText("Câbles"); while (foundElement != null) { // Get the text object from the element var foundTex

您好,我尝试在我的谷歌文档中检测特定的字符串,并将其设置为“粗体”。 我试过这个:

function bold() {
var body = DocumentApp.getActiveDocument().getBody();
var foundElement = body.findText("Câbles");

while (foundElement != null) {
    // Get the text object from the element
    var foundText = foundElement.getElement().asText();

    // Change the weight
    foundText.setFontWeight("bold");

    // Find the next match
    foundElement = body.findText("Câbles", foundElement);
}
}
脚本返回错误:TypeError:FontAction setFontWeight未在文本对象中找到

你能帮我吗?谢谢

编辑>

我试着用这个,但是粗体风格现在应用到了整个段落,不仅仅是文本字符串

function bold() {
var body = DocumentApp.getActiveDocument().getBody();
var foundElement = body.findText("test");

while (foundElement != null) {
    // Get the text object from the element
    var foundText = foundElement.getElement().asText();

    // Set Bold
    foundText.setBold(true);

    // Find the next match
    foundElement = body.findText("test", foundElement);
}
}

看起来这是通过工作表而不是文档支持的

在文档中,您可以尝试更改字体大小吗

 // Change the weight
   foundText.setFontSize(99);
好的,我这样做了:

function bold() {
var body = DocumentApp.getActiveDocument().getBody();
var foundElement = body.findText("test");

while (foundElement != null) {
    // Get the text object from the element
    var foundText = foundElement.getElement().asText();

    // Where in the element is the found text?
    var start = foundElement.getStartOffset();
    var end = foundElement.getEndOffsetInclusive();

    // Set Bold
    foundText.setBold(start, end, true);

    // Find the next match
    foundElement = body.findText("test", foundElement);
   }
}

我还尝试了“foundText.setBold(粗体)”;“its returning me”ReferenceError:“bold”未定义):/您会注意到它是documents类的一部分,但不是我尝试使用foundText.setBold(true)的工作表的一部分,但粗体样式应用于全文段落,而不仅仅是文本字符串。