Google Apps Script API
    Preparing search index...

    Access and modify protected ranges and sheets. A protected range can protect either a static range of cells or a named range. A protected sheet may include unprotected regions. For spreadsheets created with the older version of Google Sheets, use the PageProtection class instead.

    // Protect range A1:B10, then remove all other users from the list of editors.
    var ss = SpreadsheetApp.getActive();
    var range = ss.getRange('A1:B10');
    var protection = range.protect().setDescription('Sample protected range');
    
    // Ensure the current user is an editor before removing others. Otherwise, if the user's edit
    // permission comes from a group, the script throws an exception upon removing the group.
    var me = Session.getEffectiveUser();
    protection.addEditor(me);
    protection.removeEditors(protection.getEditors());
    if (protection.canDomainEdit()) {
      protection.setDomainEdit(false);
    }
    
    // Remove all range protections in the spreadsheet that the user has permission to edit.
    var ss = SpreadsheetApp.getActive();
    var protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE);
    for (var i = 0; i < protections.length; i++) {
      var protection = protections[i];
      if (protection.canEdit()) {
        protection.remove();
      }
    }
    
    // Protect the active sheet, then remove all other users from the list of editors.
    var sheet = SpreadsheetApp.getActiveSheet();
    var protection = sheet.protect().setDescription('Sample protected sheet');
    
    // Ensure the current user is an editor before removing others. Otherwise, if the user's edit
    // permission comes from a group, the script throws an exception upon removing the group.
    var me = Session.getEffectiveUser();
    protection.addEditor(me);
    protection.removeEditors(protection.getEditors());
    if (protection.canDomainEdit()) {
      protection.setDomainEdit(false);
    }
    
    interface Protection {
        addEditor(emailAddress: string): Protection;
        addEditor(user: GoogleAppsScript.Base.User): Protection;
        addEditors(emailAddresses: string[]): Protection;
        canDomainEdit(): boolean;
        canEdit(): boolean;
        getDescription(): string;
        getEditors(): GoogleAppsScript.Base.User[];
        getProtectionType(): ProtectionType;
        getRange(): GoogleAppsScript.Spreadsheet.Range;
        getRangeName(): string;
        getUnprotectedRanges(): GoogleAppsScript.Spreadsheet.Range[];
        isWarningOnly(): boolean;
        remove(): void;
        removeEditor(emailAddress: string): Protection;
        removeEditor(user: GoogleAppsScript.Base.User): Protection;
        removeEditors(emailAddresses: string[]): Protection;
        removeEditors(users: GoogleAppsScript.Base.User[]): Protection;
        setDescription(description: string): Protection;
        setDomainEdit(editable: boolean): Protection;
        setNamedRange(
            namedRange: GoogleAppsScript.Spreadsheet.NamedRange,
        ): Protection;
        setRange(range: GoogleAppsScript.Spreadsheet.Range): Protection;
        setRangeName(rangeName: string): Protection;
        setUnprotectedRanges(
            ranges: GoogleAppsScript.Spreadsheet.Range[],
        ): Protection;
        setWarningOnly(warningOnly: boolean): Protection;
    }
    Index

    Methods