Trait

com.google.appsscript.spreadsheet

Protection

Related Doc: package spreadsheet

Permalink

trait Protection extends Object

Protection 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 will throw 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 will throw an exception upon removing the group. var me = Session.getEffectiveUser(); protection.addEditor(me); protection.removeEditors(protection.getEditors()); if (protection.canDomainEdit()) { protection.setDomainEdit(false); }

Annotations
@RawJSType()
Linear Supertypes
Object, Any, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Protection
  2. Object
  3. Any
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def addEditor(user: User): Protection

    Permalink

    Adds the given user to the list of editors for the protected sheet or range.

    Adds the given user to the list of editors for the protected sheet or range. This method does not automatically give the user permission to edit the spreadsheet itself; to do that in addition, call Spreadsheet.addEditor(user).

  5. def addEditor(emailAddress: String): Protection

    Permalink

    Adds the given user to the list of editors for the protected sheet or range.

    Adds the given user to the list of editors for the protected sheet or range. This method does not automatically give the user permission to edit the spreadsheet itself; to do that in addition, call Spreadsheet.addEditor(emailAddress).

  6. def addEditors(emailAddresses: Array[String]): Protection

    Permalink

    Adds the given array of users to the list of editors for the protected sheet or range.

    Adds the given array of users to the list of editors for the protected sheet or range. This method does not automatically give the users permission to edit the spreadsheet itself; to do that in addition, call Spreadsheet.addEditors(emailAddresses).

  7. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  8. def canDomainEdit(): Boolean

    Permalink

    Determines whether all users in the domain that owns the spreadsheet have permission to edit the protected range or sheet.

    Determines whether all users in the domain that owns the spreadsheet have permission to edit the protected range or sheet. Throws an exception if the user does not have permission to edit the protected range or sheet.

  9. def canEdit(): Boolean

    Permalink

    Determines whether the user has permission to edit the protected range or sheet.

    Determines whether the user has permission to edit the protected range or sheet. The spreadsheet owner is always able to edit protected ranges and sheets.

  10. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  11. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  12. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  13. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  14. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  15. def getDescription(): String

    Permalink

    Gets the description of the protected range or sheet.

    Gets the description of the protected range or sheet. If no description is set, this method returns an empty string.

  16. def getEditors(): Array[User]

    Permalink

    Gets the list of editors for the protected range or sheet.

    Gets the list of editors for the protected range or sheet. Throws an exception if the user does not have permission to edit the protected range or sheet.

  17. def getProtectionType(): ProtectionType

    Permalink

    Gets the type of the protected area, either SpreadsheetApp.ProtectionType.RANGE or SpreadsheetApp.ProtectionType.SHEET.

  18. def getRange(): Range

    Permalink

    Gets the range that is being protected.

    Gets the range that is being protected. If the protection applies to the sheet instead of a range, this method returns a range that spans the entire sheet.

  19. def getRangeName(): String

    Permalink

    Gets the name of the protected range if it is associated with a named range.

    Gets the name of the protected range if it is associated with a named range. Returns null if the protection is not associated with a named range. Note that scripts must explicitly call setRangeName(rangeName) to associate a protected range with a named range; calling Range.protect() to create a protection from a Range that happens to be a named range, without calling setRangeName(rangeName), is not sufficient to associate them. However, creating a protected range from a named range in the Google Sheets UI will associate them automatically.

  20. def getUnprotectedRanges(): Array[Range]

    Permalink

    Gets an array of unprotected ranges within a protected sheet.

    Gets an array of unprotected ranges within a protected sheet. If the Protection object corresponds to a protected range instead of a protected sheet, this method returns an empty array. To change the unprotected ranges, use setUnprotectedRanges(ranges) to set a new array of ranges; to re-protect the entire sheet, set an empty array.

  21. def hasOwnProperty(v: String): Boolean

    Permalink
    Definition Classes
    Object
  22. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  23. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  24. def isPrototypeOf(v: Object): Boolean

    Permalink
    Definition Classes
    Object
  25. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  26. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  27. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  28. def propertyIsEnumerable(v: String): Boolean

    Permalink
    Definition Classes
    Object
  29. def remove(): Unit

    Permalink

    Unprotects the range or sheet.

  30. def removeEditor(user: User): Protection

    Permalink

    Removes the given user from the list of editors for the protected sheet or range.

    Removes the given user from the list of editors for the protected sheet or range. Note that if the user is a member of a Google Group that has edit permission, or if all users in the domain have edit permission, the user will still be able to edit the protected area as well. Neither the owner of the spreadsheet nor the current user can be removed.

  31. def removeEditor(emailAddress: String): Protection

    Permalink

    Removes the given user from the list of editors for the protected sheet or range.

    Removes the given user from the list of editors for the protected sheet or range. Note that if the user is a member of a Google Group that has edit permission, or if all users in the domain have edit permission, the user will still be able to edit the protected area. Neither the owner of the spreadsheet nor the current user can be removed.

  32. def removeEditors(emailAddresses: Array[String]): Protection

    Permalink

    Removes the given array of users from the list of editors for the protected sheet or range.

    Removes the given array of users from the list of editors for the protected sheet or range. Note that if any of the users are members of a Google Group that has edit permission, or if all users in the domain have edit permission, those users will still be able to edit the protected area. Neither the owner of the spreadsheet nor the current user can be removed.

  33. def setDescription(description: String): Protection

    Permalink

    Sets the description of the protected range or sheet.

  34. def setDomainEdit(editable: Boolean): Protection

    Permalink

    Sets whether all users in the domain that owns the spreadsheet have permission to edit the protected range or sheet.

    Sets whether all users in the domain that owns the spreadsheet have permission to edit the protected range or sheet. Note that any users who have explicit edit permission will be able to edit the protected area regardless of this setting. Throws an exception if the spreadsheet does not belong to a Google Apps domain (that is, if it is owned by a gmail.com account).

  35. def setRange(range: Range): Protection

    Permalink

    Adjusts the range that is being protected.

    Adjusts the range that is being protected. If the given range covers a different area from the current protected range, this method moves the protection to cover the new range instead.

  36. def setRangeName(rangeName: String): Protection

    Permalink

    Associates the protected range with an existing named range.

    Associates the protected range with an existing named range. If the named range covers a different area from the current protected range, this method moves the protection to cover the the named range instead. The named range must be on the same sheet as the current protected range. Note that scripts must explicitly call this method to associate a protected range with a named range; calling Range.protect() to create a protection from a Range that happens to be a named range, without calling setRangeName(rangeName), is not sufficient to associate them. However, creating a protected range from a named range in the Google Sheets UI will associate them automatically.

  37. def setUnprotectedRanges(ranges: Array[Range]): Protection

    Permalink

    Unprotects the given array of ranges within a protected sheet.

    Unprotects the given array of ranges within a protected sheet. Throws an exception if the Protection object corresponds to a protected range instead of a protected sheet or if any of the ranges are not on the protected sheet. To change the unprotected ranges, set a new array of ranges; to re-protect the entire sheet, set an empty array.

  38. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  39. def toLocaleString(): String

    Permalink
    Definition Classes
    Object
  40. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  41. def valueOf(): Any

    Permalink
    Definition Classes
    Object
  42. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  43. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  44. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Object

Inherited from Any

Inherited from AnyRef

Inherited from Any

Ungrouped