Javascript 向“添加更改格式功能”的脚本;查找并替换“;特征

Javascript 向“添加更改格式功能”的脚本;查找并替换“;特征,javascript,google-apps-script,google-sheets,Javascript,Google Apps Script,Google Sheets,谷歌文档的新脚本,目前正在寻找一个现有的脚本添加更改格式功能,以“查找和替换”功能。例如,选择B列,查找单词的每个实例,使用“查找并替换”,而不是只能替换单词,具有将格式更改为粗体或斜体的功能 我已经搜索过了,自己也没能找到任何东西,所以如果有人知道一个脚本,我将不胜感激 如果没有,请有人给我一个提示,从哪里开始,关于创建这个脚本自己 谢谢 您可以使用此代码查找和替换Google文档中的文本,但是如果您想更改已查找文本的格式,则需要修改此代码 function replaceInSheet(sh

谷歌文档的新脚本,目前正在寻找一个现有的脚本添加更改格式功能,以“查找和替换”功能。例如,选择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);
}