In a Google Spreadsheet called Attendance there is a sheet called Template. The user duplicates this sheet, renames the sheet with current date and uses this sheet to mark attendance for students. The Template sheet contains protected cells and the attendance is marked by entering Student's ID number in the space given (unprotected cells). I use the following script to duplicate multiple sheets and rename them everyday:
function createDailyAttendance() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var refss = ss.getSheetByName("DataPointers");
// Get the range Row and Column information.
var dataRangeRow = refss.getRange("K2").getValue();
//var dataRangeCol = ss.getRangeByName(ColName).getValue();
// Get the range of cells that store Duplicate sheet name.
var AttendanceDataRange = refss.getRange(dataRangeRow);
var AttendanceObjects = AttendanceDataRange.getValues();
var template = ss.getSheetByName('Template');
for (var i=0; i < AttendanceObjects.length; i++) {
// Put the sheet you want to create in a variable
var sheet = ss.getSheetByName(AttendanceObjects[i]);
// Check if the sheet you want to create already exists. If so,
// log this and loop back. If not, create the new sheet.
if (sheet) {
Logger.log("Sheet " + AttendanceObjects[i] + "already exists");
} else {
template.copyTo(ss).setName(AttendanceObjects[i]);
}
}
return;
}
This script helps me create multiple copies of sheets from Template but the duplicate copies do not retain the Cell/Range permissions.
Is there a way to add a loop function which extracts permission from Template and applies it every time the loop template.copyTo
creates a sheet?