Class PageProtection
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
محافظت از صفحه منسوخ شده است. برای صفحات گسترده ایجاد شده در نسخه جدیدتر Google Sheets، به جای آن از کلاس Protection
قدرتمندتر استفاده کنید. اگرچه این کلاس منسوخ شده است، اما برای سازگاری با نسخه قدیمی کاربرگنگار همچنان در دسترس است.
به برگههای محافظت شده در نسخه قدیمی Google Sheets دسترسی داشته باشید و آنها را اصلاح کنید.
روش های منسوخ شده
روش | نوع برگشت | شرح مختصر |
---|
add User(email)
| void | کاربر را به لیست کاربرانی اضافه می کند که می توانند برگه را ویرایش کنند، در صورتی که محافظت شده باشد. |
get Users()
| String[] | فهرستی از آدرسهای ایمیل کاربرانی را که میتوانند این برگه را ویرایش کنند، برمیگرداند. |
is Protected()
| Boolean | نشان می دهد که آیا صفحه محافظ صفحه فعال است یا خیر. |
remove User(user)
| void | کاربری را از لیست کاربرانی که می توانند برگه را ویرایش کنند حذف می کند. |
set Protected(protection)
| void | وضعیت حفاظتی ورق را تنظیم می کند. |
روش های منسوخ شده
add User(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 | ایمیل کاربر برای افزودن. |
همچنین ببینید
get Users()
منسوخ شده است. این تابع منسوخ شده است و نباید در اسکریپت های جدید استفاده شود.
فهرستی از آدرسهای ایمیل کاربرانی را که میتوانند این برگه را ویرایش کنند، برمیگرداند.
اگر محافظت برگه غیرفعال باشد، مقدار بازگردانده شده توسط این تماس بی معنی است.
بازگشت
String[]
- آرایه ای از آدرس های ایمیل کاربرانی که می توانند این برگه را ویرایش کنند.
is Protected()
منسوخ شده است. این تابع منسوخ شده است و نباید در اسکریپت های جدید استفاده شود.
نشان می دهد که آیا صفحه محافظ صفحه فعال است یا خیر.
// Determine whether or not sheet protection is enabled
const sheet = SpreadsheetApp.getActiveSheet();
const permissions = sheet.getSheetProtection();
const isProtected = permissions.isProtected();
بازگشت
Boolean
- اینکه آیا صفحه محافظ صفحه فعال است یا خیر.
همچنین ببینید
remove User(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 | آدرس ایمیل کاربر برای حذف. |
همچنین ببینید
set Protected(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 برای غیرفعال کردن محافظت صفحه. |
همچنین ببینید
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-12 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-12 بهوقت ساعت هماهنگ جهانی."],[[["\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())"]]