我的功能正常
它通过其标题找到一列,然后tt在直径上将一列中的像元值拆分,然后替换这些片段的值,然后将它们重新连接为字符串
并对标题列表中的所有列重复
有点缠绵,但令我惊讶的是它的工作原理还不错
我需要协助的问题是,它在每个标头上发回,怎么使它仅发回一次?
我试图弄清楚,但无济于事
谢谢
function FindRsplace(shtName, frshtName, cheaders, frheaders, dilm1, dilm2) {
var sheet = SpreadsheetApp.getActive().getSheetByName(shtName);
var hn =[];
var fhn = [];
//Array of column indices from column headers
for (var k = 0; k <= cheaders.length-1; k++) {
hn[k] = HTN(shtName,cheaders[k]) - 1;
fhn[k] = HTN(frshtName,frheaders[k]);
}
for (var j = 0; j <= cheaders.length-1; j++) {
var frSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(frshtName);
var frLR = GLR(frshtName,frheaders[j],2); // Get the last row of the Search column NOT of the Sheet
var frRange = frSheet.getRange(2, fhn[j], frLR, 2);
var frValues = frRange.getValues();
// Read Height only once
var maxHeight = Range.getLastRow();
// Read all values and formulas at once
var rangeValues = Range.getValues();
// iterate through all cells in the selected range Look in Sheet
for (var cellRow = 0; cellRow < maxHeight; cellRow++) {
for (var i = 0; i < frValues.length; i++) {
//FindReplace string fragments
rangeValues[cellRow][hn[j]] = rangeValues[cellRow][hn[j]].toString().split(frValues[i][0]+dilm1).join(frValues[i][1]+dilm2).trim();
//Replaceing the last fragment or the only string without dilimeter
rangeValues[cellRow][hn[j]] = rangeValues[cellRow][hn[j]].toString().split(frValues[i][0]).join(frValues[i][1]).trim();
}
}
Range.setValues(rangeValues);
SpreadsheetApp.flush();
}
}
function FindRsplace_n() {
FindRsplace(
'sheet1', 'FindReplace',
["HeaderA", "HeaderB", "HeaderC"],
["frHeaderA", "frHeaderB", "frHeaderC"]],
",",
"|"
);
}