gpt4 book ai didi

javascript - 将查找和替换限制为整个单词 google sheets .gs 函数

转载 作者:行者123 更新时间:2023-11-30 20:52:04 25 4
gpt4 key购买 nike

<分区>

我有一个查找和替换函数,它替换字符串中 aaevery 实例,在 VBA 中它将是 xlPart

有没有办法设置该函数,使其替换整个单词或VBA语言xlWhole

谢谢

function FindReplaceWSHT(){

replaceInSheet("Elements",'aa','ZZZ');
}

function replaceInSheet(shtName, to_replace, replace_with) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(shtName);

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

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