I developed a document management system built with about 25 Google spreadsheets interlinked with many IMPORTRANGEs. For a new project I have to duplicate the system and relink the spreadsheets.
I can do it like this
function replaceEverywhere() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var textFinder = sheet.createTextFinder('Old_01');
textFinder.replaceAllWith('New_01');
var textFinder = sheet.createTextFinder('Old_02');
textFinder.replaceAllWith('New_02');
var textFinder = sheet.createTextFinder('Old_25');
textFinder.replaceAllWith('New_25');
}
but I'd like to use a foreach
with two lists, one with the old urls an the other with the new url.
CodePudding user response:
Try this:
function replaceEverywhere() {
var ss = SpreadsheetApp.getActive();
const o = ["Old_01","Old_02","Old_03"];
const n= ["ld_01","ld_02","ld_03"];
o.forEach((e,i) => ss.createTextFinder(e).replaceAllWith(n[i]))
}