Im trying to sync sheets from a master spreadsheet to individual sheets saved together in a google folder (such that any changes in mastersheet will be displayed in the individual sheets and these would be accessible while keeping the mastersheet private). I tried using ImportRange and also using apps scripts to sync them, but only the data gets brought over and the formatting is lost. Any way to go about this?
Referenced this from Is there a way to keep two sheets synchronized?
what can i add to retain the formatting
function onOpen(e){
SpreadsheetApp.getUi().createMenu('Sync')
.addItem('Sync with accessible sheets', 'importData')
.addToUi();
}
var sourceSpreadsheetID = "id1";
var sourceWorksheetName = "name";
var destinationSpreadsheetID = "id2";
var destinationWorksheetName = "Sheet1";
function importData() {
var thisSpreadsheet = SpreadsheetApp.openById(sourceSpreadsheetID);
var thisWorksheet = thisSpreadsheet.getSheetByName(sourceWorksheetName);
var thisData = thisWorksheet.getDataRange();
var toSpreadsheet = SpreadsheetApp.openById(destinationSpreadsheetID);
var toWorksheet = toSpreadsheet.getSheetByName(destinationWorksheetName);
var toRange = toWorksheet.getRange(1, 1, thisData.getNumRows(), thisData.getNumColumns())
toRange.setValues(thisData.getValues());
}
noxxe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.