PageProtection


**Deprecated.** For spreadsheets created in the newer version of Google Sheets, use the more powerful
`https://developers.google.com/apps-script/reference/spreadsheet/protection` class instead. Although this class is deprecated, it remains available
for compatibility with the older version of Sheets.

Access and modify protected sheets in the older version of Google Sheets.

### Deprecated methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/spreadsheet/page-protection#addUser(String)` | `void` | Adds a user to the list of users who can edit the sheet, if it is protected. |
| `https://developers.google.com/apps-script/reference/spreadsheet/page-protection#getUsers()` | `String[]` | Returns a list of the email addresses of the users who can edit this sheet. |
| `https://developers.google.com/apps-script/reference/spreadsheet/page-protection#isProtected()` | `Boolean` | Indicates whether the sheet has sheet protection enabled or not. |
| `https://developers.google.com/apps-script/reference/spreadsheet/page-protection#removeUser(String)` | `void` | Removes a user from the list of users who can edit the sheet. |
| `https://developers.google.com/apps-script/reference/spreadsheet/page-protection#setProtected(Boolean)` | `void` | Sets the protection status for the sheet. |

## Deprecated methods

### `addUser(email)`


**Deprecated.** This function is deprecated and should not be used in new scripts.

Adds a user to the list of users who can edit the sheet, if it is protected.

```javascript
// Add the "user@example.com" user to the list of users who can edit this sheet
const sheet = SpreadsheetApp.getActiveSheet();
const permissions = sheet.getSheetProtection();
permissions.addUser('user@example.com');
permissions.setProtected(true);
sheet.setSheetProtection(permissions);
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `email` | `String` | The email of the user to add. |

#### See also

- `https://developers.google.com/apps-script/reference/spreadsheet/page-protection#removeUser(String)`

*** ** * ** ***

### `getUsers()`


**Deprecated.** This function is deprecated and should not be used in new scripts.

Returns a list of the email addresses of the users who can edit this sheet.

If sheet protection is disabled, the value returned by this call is meaningless.

#### Return


`String[]` --- An array of email addresses of users who can edit this sheet.

*** ** * ** ***

### `isProtected()`


**Deprecated.** This function is deprecated and should not be used in new scripts.

Indicates whether the sheet has sheet protection enabled or not.

```javascript
// Determine whether or not sheet protection is enabled
const sheet = SpreadsheetApp.getActiveSheet();
const permissions = sheet.getSheetProtection();
const isProtected = permissions.isProtected();
```

#### Return


`Boolean` --- Whether the sheet has sheet protection enabled or not.

#### See also

- `https://developers.google.com/apps-script/reference/spreadsheet/page-protection#setProtected(Boolean)`

*** ** * ** ***

### `removeUser(user)`


**Deprecated.** This function is deprecated and should not be used in new scripts.

Removes a user from the list of users who can edit the sheet.

```javascript
// Remove the "user@example.com" user to the list of users who can edit this
// sheet
const sheet = SpreadsheetApp.getActiveSheet();
const permissions = sheet.getSheetProtection();
permissions.removeUser('user@example.com');
permissions.setProtected(true);
sheet.setSheetProtection(permissions);
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `user` | `String` | The email address of the user to remove. |

#### See also

- `https://developers.google.com/apps-script/reference/spreadsheet/page-protection#addUser(String)`

*** ** * ** ***

### `setProtected(protection)`


**Deprecated.** This function is deprecated and should not be used in new scripts.

Sets the protection status for the sheet.

```javascript
// Enables sheet protection for  this sheet
const sheet = SpreadsheetApp.getActiveSheet();
const permissions = sheet.getSheetProtection();
permissions.setProtected(true);
sheet.setSheetProtection(permissions);
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `protection` | `Boolean` | `true` to enable sheet protection, `false` to disable sheet protection. |

#### See also

- `https://developers.google.com/apps-script/reference/spreadsheet/page-protection#isProtected()`