gpt4 book ai didi

google-apps-script - 在文档中使用谷歌应用程序脚本选择文本

转载 作者:行者123 更新时间:2023-12-03 03:31:05 25 4
gpt4 key购买 nike

应用程序脚本是否可以突出显示(如选择)文本?我想从菜单运行脚本,然后选择某些文本的所有匹配实例,以便可以一次性格式化它们。

具体来说,我想编写一个脚本来突出显示 Google 文档中的所有脚注,以便可以同时对它们进行格式化。我是文档脚注造型师插件的创建者,它允许用户设置脚注的样式。但我想包含使用任何格式的选项,而不必在添加本身中包含每个可用的格式选项。

最佳答案

跳过突出显示部分并直接格式化它们怎么样?下面的代码搜索单词“Testing”并将其加粗并突出显示为黄色。希望这会有所帮助。

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

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);

// Change the background color to yellow
foundText.setBackgroundColor(start, end, "#FCFC00");

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

关于google-apps-script - 在文档中使用谷歌应用程序脚本选择文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42921053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com