一个人能否帮助我把这一保护范围之广的文字变成一个有多种不同例外情况的保护表? 在使用这一文字时,除范围外,还制作15份复印件,但复印件没有保护。 感谢!
function combineScripts() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheetToCopy = ss.getSheetByName( Monthly Budget );
for (let i = 1; i < 15; i++) {
const newSheet = copySheetWithProtections\_(sheetToCopy, `Monthly Copy ${i}`);
}
const sourceSheet = ss.getSheetByName( Monthly Budget );
const copiedSheet = sourceSheet.copyTo(ss).setName( Monthly Copy );
const protections = sourceSheet.getProtections(SpreadsheetApp.ProtectionType.RANGE);
protections.forEach(p => {
const rangeNotation = p.getRange().getA1Notation();
const copiedProtection = copiedSheet.getRange(rangeNotation).protect();
copiedProtection.setDescription(p.getDescription());
copiedProtection.setWarningOnly(p.isWarningOnly());
if (!p.isWarningOnly()) {
copiedProtection.removeEditors(copiedProtection.getEditors());
copiedProtection.addEditors(p.getEditors());
}
});
}
function copySheetWithProtections\_(sourceSheet, newName) {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const newSheet = sourceSheet.copyTo(ss);
newSheet.setName(newName);
const protections = sourceSheet.getProtections(SpreadsheetApp.ProtectionType.RANGE);
protections.forEach(p => {
const rangeNotation = p.getRange().getA1Notation();
const copiedProtection = newSheet.getRange(rangeNotation).protect();
copiedProtection.setDescription(p.getDescription());
copiedProtection.setWarningOnly(p.isWarningOnly());
if (!p.isWarningOnly()) {
copiedProtection.removeEditors(copiedProtection.getEditors());
copiedProtection.addEditors(p.getEditors());
}
});
return newSheet;
}