gpt4 book ai didi

javascript - 将更改格式功能添加到 "Find and Replace"功能的脚本

转载 作者:行者123 更新时间:2023-12-03 02:50:36 24 4
gpt4 key购买 nike

Google 文档脚本新手,目前正在寻找现有脚本以向“查找和替换”功能添加更改格式功能。例如,选择 B 列,查找单词的每个实例,使用“查找和替换”,并且不仅能够替换单词,还具有将格式更改为粗体或斜体的功能。

我自己搜索过但找不到任何东西,所以如果有人知道脚本,我将不胜感激。

如果没有,有人可以给我一个提示,告诉我从哪里开始,关于我自己创建这个脚本。

谢谢。

最佳答案

您可以使用此代码在 Google 文档中查找和替换文本,但如果您想更改找到的文本的格式,则需要对其进行修改。

function replaceInSheet(sheet, to_replace, replace_with) {
//get the current data range values as an array
var values = sheet.getDataRange().getValues();

//loop over the rows in the array
for(var row in values){

//use Array.map to execute a replace call on each of the cells in the row.
var replaced_values = values[row].map(function(original_value){
return original_value.toString().replace(to_replace,replace_with);
});

//replace the original row values with the replaced values
values[row] = replaced_values;
}

//write the updated values to the sheet
sheet.getDataRange().setValues(values);
}

关于javascript - 将更改格式功能添加到 "Find and Replace"功能的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47878010/

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