你好,我尝试检测我的谷歌文档中的特定字符串,并将其设置为“粗体”。 香港专业教育学院尝试这样:如何使用谷歌脚本替换字体重量?
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);
}
}
脚本返回我一个错误:类型错误:Fonction 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);
}
}
我用尽。这项工作,并改变字体大小。 –
我也尝试过“foundText.setBold(bold);”它返回我“ReferenceError:”粗体“未定义”:/ –
你会注意到它是文档类的一部分:https://developers.google.com/apps-script/reference/document/document – OblongMedulla