We are a team of 4-5 people. We have a "template" spreadsheet that we duplicate for each new lead/client. On duplication, the scripts associated to that template spreadsheet are duplicated and of course they are not synchronised (if I wanted to update/add a function on all the "clients" spreadsheets, I'd have to do it on each of them manually)
This week, I finally tried and managed to create an add-on, which solves this problem and will make everything more efficient when it comes to updating scripts and adding new features.
This is great, but I'm wondering if it is possible to go further. What if, instead of a script, I want to modify the content of a cell or a formula in all the clients spreadsheets ? Or add a column or even a worksheet, in all the client spreadsheets?
Is there a way to "bulk-edit" multiple spreadsheets at the same time? It seems unlikely but you never know...
Otherwise, are there methods to keep my clients spreadsheets better synchronised?
CodePudding user response:
To add to the comment. Here is some boilerplate code:
/**
*
* @param {string} targetSheet sheetname where the change is made
* @param {string} tartgetRange A1 notation of the change(s) (assumes an 2d array)
* @param {array} data the values or formulas
* @param {"values"|"formulas"} type the type of values.
*/
function pushToChild(targetSheet, tartgetRange, data, type){
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName('Childeren');
const ids = sheet.getRange(2,1, sheet.getLastRow() - 1).getValues().flat();
ids.forEach(id => {
const tss = SpreadsheetApp.openById(id)
const tSheet = tss.getSheetByName(targetSheet)
const range = tSheet.getRange(tartgetRange)
if(type == "values"){
range.setValues(data)
} else if(type == "formulas"){
range.setFormulas(data)
} else {
throw new Error('No valid type is given')
}
})
}
function createChange(){
pushToChild('Summary', 'A1', [['This is updated!']], "values")
}