Class PageProtection
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
การป้องกันหน้า
เลิกใช้งานแล้ว สำหรับสเปรดชีตที่สร้างใน Google ชีตเวอร์ชันใหม่กว่า ให้ใช้คลาส Protection
ที่มีประสิทธิภาพมากกว่าแทน แม้ว่าคลาสนี้จะเลิกใช้งานแล้ว แต่ก็ยังคงพร้อมใช้งาน
เพื่อความเข้ากันได้กับชีตเวอร์ชันเก่า
เข้าถึงและแก้ไขชีตที่ป้องกันใน Google ชีตเวอร์ชันเก่า
วิธีการที่เลิกใช้งานแล้ว
addUser(email)
เลิกใช้งานแล้ว เลิกใช้งานฟังก์ชันนี้แล้วและไม่ควรใช้ในสคริปต์ใหม่
เพิ่มผู้ใช้ลงในรายชื่อผู้ใช้ที่แก้ไขชีตได้ หากชีตได้รับการป้องกัน
// 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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
email | String | อีเมลของผู้ใช้ที่จะเพิ่ม |
ดูเพิ่มเติม
getUsers()
เลิกใช้งานแล้ว เลิกใช้งานฟังก์ชันนี้แล้วและไม่ควรใช้ในสคริปต์ใหม่
แสดงผลรายการอีเมลของผู้ใช้ที่แก้ไขชีตนี้ได้
หากปิดใช้การปกป้องชีต ค่าที่การเรียกนี้แสดงผลจะไม่มีความหมาย
รีเทิร์น
String[]
— อาร์เรย์ของอีเมลของผู้ใช้ที่แก้ไขชีตนี้ได้
isProtected()
เลิกใช้งานแล้ว เลิกใช้งานฟังก์ชันนี้แล้วและไม่ควรใช้ในสคริปต์ใหม่
ระบุว่าชีตเปิดใช้การปกป้องชีตหรือไม่
// Determine whether or not sheet protection is enabled
const sheet = SpreadsheetApp.getActiveSheet();
const permissions = sheet.getSheetProtection();
const isProtected = permissions.isProtected();
รีเทิร์น
Boolean
— ชีตเปิดใช้การป้องกันชีตหรือไม่
ดูเพิ่มเติม
removeUser(user)
เลิกใช้งานแล้ว เลิกใช้งานฟังก์ชันนี้แล้วและไม่ควรใช้ในสคริปต์ใหม่
นำผู้ใช้ออกจากรายชื่อผู้ใช้ที่แก้ไขชีตได้
// 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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
user | String | อีเมลของผู้ใช้ที่จะนำออก |
ดูเพิ่มเติม
setProtected(protection)
เลิกใช้งานแล้ว เลิกใช้งานฟังก์ชันนี้แล้วและไม่ควรใช้ในสคริปต์ใหม่
ตั้งค่าสถานะการป้องกันสำหรับชีต
// Enables sheet protection for this sheet
const sheet = SpreadsheetApp.getActiveSheet();
const permissions = sheet.getSheetProtection();
permissions.setProtected(true);
sheet.setSheetProtection(permissions);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
protection | Boolean | true เพื่อเปิดใช้การป้องกันชีต false เพื่อปิดใช้การป้องกันชีต
|
ดูเพิ่มเติม
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-13 UTC
[null,null,["อัปเดตล่าสุด 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())"]]