Class PageProtection
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Bảo vệtrang
Không dùng nữa. Đối với bảng tính được tạo trong phiên bản Google Trang tính mới hơn, hãy sử dụng lớp Protection
mạnh mẽ hơn. Mặc dù lớp này không được dùng nữa, nhưng vẫn có sẵn để tương thích với phiên bản cũ của Trang tính.
Truy cập và sửa đổi các trang tính được bảo vệ trong phiên bản cũ của Google Trang tính.
Các phương thức ngừng hoạt động
Phương thức | Kiểu dữ liệu trả về | Mô tả ngắn |
addUser(email)
| void | Thêm người dùng vào danh sách người dùng có thể chỉnh sửa trang tính (nếu trang tính được bảo vệ). |
getUsers()
| String[] | Trả về danh sách địa chỉ email của những người dùng có thể chỉnh sửa trang tính này. |
isProtected()
| Boolean | Cho biết liệu trang tính có bật tính năng bảo vệ trang tính hay không. |
removeUser(user)
| void | Xoá một người dùng khỏi danh sách những người dùng có thể chỉnh sửa trang tính. |
setProtected(protection)
| void | Đặt trạng thái bảo vệ cho trang tính. |
Các phương thức ngừng hoạt động
addUser(email)
Không dùng nữa. Hàm này không còn được dùng nữa và bạn không nên sử dụng trong các tập lệnh mới.
Thêm người dùng vào danh sách người dùng có thể chỉnh sửa trang tính (nếu trang tính được bảo vệ).
// 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);
Thông số
Tên | Loại | Mô tả |
email | String | Email của người dùng cần thêm. |
Xem thêm
getUsers()
Không dùng nữa. Hàm này không còn được dùng nữa và bạn không nên sử dụng trong các tập lệnh mới.
Trả về danh sách địa chỉ email của những người dùng có thể chỉnh sửa trang tính này.
Nếu tính năng bảo vệ trang tính bị vô hiệu hoá, thì giá trị do lệnh gọi này trả về sẽ không có ý nghĩa.
Cầu thủ trả bóng
String[]
– Một mảng địa chỉ email của những người dùng có thể chỉnh sửa trang tính này.
isProtected()
Không dùng nữa. Hàm này không còn được dùng nữa và bạn không nên sử dụng trong các tập lệnh mới.
Cho biết liệu trang tính có bật tính năng bảo vệ trang tính hay không.
// Determine whether or not sheet protection is enabled
const sheet = SpreadsheetApp.getActiveSheet();
const permissions = sheet.getSheetProtection();
const isProtected = permissions.isProtected();
Cầu thủ trả bóng
Boolean
– Trang tính có bật chế độ bảo vệ trang tính hay không.
Xem thêm
removeUser(user)
Không dùng nữa. Hàm này không còn được dùng nữa và bạn không nên sử dụng trong các tập lệnh mới.
Xoá một người dùng khỏi danh sách những người dùng có thể chỉnh sửa trang tính.
// 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);
Thông số
Tên | Loại | Mô tả |
user | String | Địa chỉ email của người dùng cần xoá. |
Xem thêm
setProtected(protection)
Không dùng nữa. Hàm này không còn được dùng nữa và bạn không nên sử dụng trong các tập lệnh mới.
Đặt trạng thái bảo vệ cho trang tính.
// Enables sheet protection for this sheet
const sheet = SpreadsheetApp.getActiveSheet();
const permissions = sheet.getSheetProtection();
permissions.setProtected(true);
sheet.setSheetProtection(permissions);
Thông số
Tên | Loại | Mô tả |
protection | Boolean | true để bật tính năng bảo vệ trang tính, false để tắt tính năng bảo vệ trang tính. |
Xem thêm
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-13 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-13 UTC."],[[["\u003cp\u003eThe \u003ccode\u003ePageProtection\u003c/code\u003e class is deprecated and should not be used in new scripts for spreadsheets created in the newer version of Google Sheets.\u003c/p\u003e\n"],["\u003cp\u003eUse the \u003ccode\u003eProtection\u003c/code\u003e class instead for newer Google Sheets for more powerful sheet protection features.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003ePageProtection\u003c/code\u003e provides methods to manage access and modifications to protected sheets in the older version of Google Sheets.\u003c/p\u003e\n"],["\u003cp\u003eDespite being deprecated, \u003ccode\u003ePageProtection\u003c/code\u003e remains available for compatibility with older Google Sheets.\u003c/p\u003e\n"],["\u003cp\u003eKey methods include adding/removing users with edit access, checking protection status, and setting protection status.\u003c/p\u003e\n"]]],[],null,["# Class PageProtection\n\nPageProtection\n\n\n**Deprecated.** For spreadsheets created in the newer version of Google Sheets, use the more powerful\n[Protection](/apps-script/reference/spreadsheet/protection) class instead. Although this class is deprecated, it remains available\nfor compatibility with the older version of Sheets.\n\nAccess and modify protected sheets in the older version of Google Sheets. \n\n### Deprecated methods\n\n| Method | Return type | Brief description |\n|----------------------------------------------------|-------------|------------------------------------------------------------------------------|\n| [addUser(email)](#addUser(String)) | `void` | Adds a user to the list of users who can edit the sheet, if it is protected. |\n| [getUsers()](#getUsers()) | `String[]` | Returns a list of the email addresses of the users who can edit this sheet. |\n| [isProtected()](#isProtected()) | `Boolean` | Indicates whether the sheet has sheet protection enabled or not. |\n| [removeUser(user)](#removeUser(String)) | `void` | Removes a user from the list of users who can edit the sheet. |\n| [setProtected(protection)](#setProtected(Boolean)) | `void` | Sets the protection status for the sheet. |\n\nDeprecated methods\n------------------\n\n### `add``User(email)`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nAdds a user to the list of users who can edit the sheet, if it is protected.\n\n```javascript\n// Add the \"user@example.com\" user to the list of users who can edit this sheet\nconst sheet = SpreadsheetApp.getActiveSheet();\nconst permissions = sheet.getSheetProtection();\npermissions.addUser('user@example.com');\npermissions.setProtected(true);\nsheet.setSheetProtection(permissions);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|----------|-------------------------------|\n| `email` | `String` | The email of the user to add. |\n\n#### See also\n\n- [removeUser(user)](#removeUser(String))\n\n*** ** * ** ***\n\n### `get``Users()`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nReturns a list of the email addresses of the users who can edit this sheet.\n\nIf sheet protection is disabled, the value returned by this call is meaningless.\n\n#### Return\n\n\n`String[]` --- An array of email addresses of users who can edit this sheet.\n\n*** ** * ** ***\n\n### `is``Protected()`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nIndicates whether the sheet has sheet protection enabled or not.\n\n```javascript\n// Determine whether or not sheet protection is enabled\nconst sheet = SpreadsheetApp.getActiveSheet();\nconst permissions = sheet.getSheetProtection();\nconst isProtected = permissions.isProtected();\n```\n\n#### Return\n\n\n`Boolean` --- Whether the sheet has sheet protection enabled or not.\n\n#### See also\n\n- [setProtected(protection)](#setProtected(Boolean))\n\n*** ** * ** ***\n\n### `remove``User(user)`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nRemoves a user from the list of users who can edit the sheet.\n\n```javascript\n// Remove the \"user@example.com\" user to the list of users who can edit this\n// sheet\nconst sheet = SpreadsheetApp.getActiveSheet();\nconst permissions = sheet.getSheetProtection();\npermissions.removeUser('user@example.com');\npermissions.setProtected(true);\nsheet.setSheetProtection(permissions);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|--------|----------|------------------------------------------|\n| `user` | `String` | The email address of the user to remove. |\n\n#### See also\n\n- [addUser(email)](#addUser(String))\n\n*** ** * ** ***\n\n### `set``Protected(protection)`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nSets the protection status for the sheet.\n\n```javascript\n// Enables sheet protection for this sheet\nconst sheet = SpreadsheetApp.getActiveSheet();\nconst permissions = sheet.getSheetProtection();\npermissions.setProtected(true);\nsheet.setSheetProtection(permissions);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|--------------|-----------|-------------------------------------------------------------------------|\n| `protection` | `Boolean` | `true` to enable sheet protection, `false` to disable sheet protection. |\n\n#### See also\n\n- [isProtected()](#isProtected())"]]