גישה לטווחים ולגיליונות מוגנים ושינוי שלהם. טווח מוגן יכול להגן על טווח סטטי של תאים או על טווח תאים בעל שם. גיליון מוגן יכול לכלול אזורים לא מוגנים. בגיליונות אלקטרוניים שנוצרו בגרסה הישנה של Google Sheets, צריך להשתמש במקום זאת במחלקה .
Page
// Protect range A1:B10, then remove all other users from the list of editors. const ss = SpreadsheetApp.getActive(); const range = ss.getRange('A1:B10'); const 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 throws an exception // upon removing the group. const 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. const ss = SpreadsheetApp.getActive(); const protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE); for (let i = 0; i < protections.length; i++) { const protection = protections[i]; if (protection.canEdit()) { protection.remove(); } }
// Protect the active sheet, then remove all other users from the list of // editors. const sheet = SpreadsheetApp.getActiveSheet(); const 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 throws an exception // upon removing the group. const me = Session.getEffectiveUser(); protection.addEditor(me); protection.removeEditors(protection.getEditors()); if (protection.canDomainEdit()) { protection.setDomainEdit(false); }
Methods
| שיטה | סוג הערך שמוחזר | תיאור קצר |
|---|---|---|
add | Protection | הפונקציה מוסיפה את המשתמש שצוין לרשימת העורכים של הגיליון או הטווח המוגנים. |
add | Protection | הפונקציה מוסיפה את המשתמש שצוין לרשימת העורכים של הגיליון או הטווח המוגנים. |
add | Protection | מוסיפה את מערך המשתמשים שצוין לרשימת העורכים של הגיליון או הטווח המוגנים. |
add | Protection | הפונקציה מוסיפה את קהל היעד שצוין כבעל הרשאת עריכה בטווח התאים המוגן. |
can | Boolean | ההגדרה קובעת אם לכל המשתמשים בדומיין שבבעלותו הגיליון האלקטרוני יש הרשאה לערוך את הטווח או הגיליון המוגנים. |
can | Boolean | המדיניות קובעת אם למשתמש יש הרשאה לערוך את הטווח או הגיליון המוגנים. |
get | String | מחזירה את התיאור של הטווח או הגיליון המוגנים. |
get | User[] | מחזירה את רשימת העורכים של הטווח או הגיליון המוגנים. |
get | Protection | מחזירה את סוג האזור המוגן, RANGE או SHEET. |
get | Range | מחזירה את הטווח שמוגן. |
get | String|null | מחזירה את השם של טווח התאים המוגן אם הוא משויך לטווח תאים בעל שם. |
get | Target | הפונקציה מחזירה את מזהי קהלי היעד שיכולים לערוך את הטווח המוגן. |
get | Range[] | מחזירה מערך של טווחים לא מוגנים בגיליון מוגן. |
is | Boolean | קובעת אם האזור המוגן משתמש בהגנה מבוססת-אזהרה. |
remove() | void | הסרת ההגנה מהטווח או מהגיליון. |
remove | Protection | הפונקציה מסירה את המשתמש שצוין מרשימת העורכים של הגיליון או הטווח המוגנים. |
remove | Protection | הפונקציה מסירה את המשתמש שצוין מרשימת העורכים של הגיליון או הטווח המוגנים. |
remove | Protection | מסירה את מערך המשתמשים שצוין מרשימת העורכים של הגיליון או הטווח המוגנים. |
remove | Protection | מסירה את קהל היעד שצוין כבעל הרשאת עריכה בטווח התאים המוגן. |
set | Protection | הגדרת התיאור של הטווח או הגיליון המוגנים. |
set | Protection | ההגדרה קובעת אם לכל המשתמשים בדומיין שבבעלותו הגיליון האלקטרוני יש הרשאה לערוך את הטווח או הגיליון המוגנים. |
set | Protection | משייך את הטווח המוגן לטווח קיים בעל שם. |
set | Protection | משנה את הטווח שמוגן. |
set | Protection | משייך את הטווח המוגן לטווח קיים בעל שם. |
set | Protection | הפונקציה מבטלת את ההגנה של מערך הטווחים הנתון בגיליון מוגן. |
set | Protection | מגדיר אם הטווח המוגן הזה משתמש בהגנה מבוססת-אזהרה. |
תיעוד מפורט
add Editor(emailAddress)
הפונקציה מוסיפה את המשתמש שצוין לרשימת העורכים של הגיליון או הטווח המוגנים. השיטה הזו לא מעניקה למשתמש הרשאה לערוך את הגיליון האלקטרוני עצמו באופן אוטומטי. כדי לעשות זאת, צריך לקרוא גם ל-Spreadsheet.addEditor(emailAddress).
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Adds an editor to the spreadsheet using an email address. // TODO(developer): Replace the email address with a valid email. ss.addEditor('cloudysanfrancisco@gmail.com'); // Gets a sheet by its name and protects it. const sheet = ss.getSheetByName('Sheet1'); const sampleProtectedSheet = sheet.protect(); // Adds an editor of the protected sheet using an email address. // TODO(developer): Replace the email address with a valid email. sampleProtectedSheet.addEditor('cloudysanfrancisco@gmail.com'); // Gets the editors of the protected sheet. const editors = sampleProtectedSheet.getEditors(); // Logs the editors' email addresses to the console. for (const editor of editors) { console.log(editor.getEmail()); }
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
email | String | כתובת האימייל של המשתמש שרוצים להוסיף. |
חזרה
Protection – האובייקט שמייצג את הגדרות ההגנה, לשרשור.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
add Editor(user)
הפונקציה מוסיפה את המשתמש שצוין לרשימת העורכים של הגיליון או הטווח המוגנים. השיטה הזו לא מעניקה למשתמש הרשאה לערוך את הגיליון האלקטרוני עצמו באופן אוטומטי. כדי לעשות זאת, צריך לקרוא גם ל-Spreadsheet.addEditor(user).
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Protects the sheet. const sampleProtectedSheet = sheet.protect(); // Adds the active user as an editor of the protected sheet. sampleProtectedSheet.addEditor(Session.getActiveUser()); // Gets the editors of the protected sheet. const editors = sampleProtectedSheet.getEditors(); // Logs the editors' email addresses to the console. for (const editor of editors) { console.log(editor.getEmail()); }
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
user | User | ייצוג של המשתמש שרוצים להוסיף. |
חזרה
Protection – האובייקט שמייצג את הגדרות ההגנה, לשרשור.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
add Editors(emailAddresses)
מוסיפה את מערך המשתמשים שצוין לרשימת העורכים של הגיליון או הטווח המוגנים. השיטה הזו לא מעניקה למשתמשים באופן אוטומטי הרשאה לערוך את הגיליון האלקטרוני עצמו. כדי לעשות זאת, צריך בנוסף לקרוא ל-Spreadsheet.addEditors(emailAddresses).
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Creates variables for the email addresses to add as editors. // TODO(developer): Replace the email addresses with valid ones. const TEST_EMAIL_1 = 'cloudysanfrancisco@gmail.com'; const TEST_EMAIL_2 = 'baklavainthebalkans@gmail.com'; // Protects the sheet. const sampleProtectedSheet = sheet.protect(); // Adds editors to the protected sheet using the email address variables. sampleProtectedSheet.addEditors([TEST_EMAIL_1, TEST_EMAIL_2]); // Gets the editors of the protected sheet. const editors = sampleProtectedSheet.getEditors(); // Logs the editors' email addresses to the console. for (const editor of editors) { console.log(editor.getEmail()); }
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
email | String[] | מערך של כתובות אימייל של המשתמשים שרוצים להוסיף. |
חזרה
Protection – האובייקט שמייצג את הגדרות ההגנה, לשרשור.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
add Target Audience(audienceId)
הפונקציה מוסיפה את קהל היעד שצוין כבעל הרשאת עריכה בטווח התאים המוגן.
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
audience | String | המזהה של קהל היעד שרוצים להוסיף. |
חזרה
Protection – האובייקט שמייצג את הגדרות ההגנה, לשרשור.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
can Domain Edit()
ההגדרה קובעת אם לכל המשתמשים בדומיין שבבעלותו הגיליון האלקטרוני יש הרשאה לערוך את הטווח או הגיליון המוגנים. מוחזרת חריגה אם למשתמש אין הרשאה לערוך את הטווח המוגן או את הגיליון.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Protects the sheet. const sampleProtectedSheet = sheet.protect(); // Logs whether domain users have permission to edit the protected sheet to the // console. console.log(sampleProtectedSheet.canDomainEdit());
חזרה
Boolean — true אם לכל המשתמשים בדומיין שבבעלותו הגיליון האלקטרוני יש הרשאה לערוך את הטווח או הגיליון המוגנים; false אם אין להם הרשאה כזו.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
can Edit()
המדיניות קובעת אם למשתמש יש הרשאה לערוך את הטווח או הגיליון המוגנים. הבעלים של הגיליון האלקטרוני תמיד יכול לערוך טווחים וגיליונות מוגנים.
// Remove all range protections in the spreadsheet that the user has permission // to edit. const ss = SpreadsheetApp.getActive(); const protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE); for (let i = 0; i < protections.length; i++) { const protection = protections[i]; if (protection.canEdit()) { protection.remove(); } }
חזרה
Boolean — true אם למשתמש יש הרשאה לערוך את הטווח או הגיליון המוגנים; false אם לא
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Description()
מחזירה את התיאור של הטווח או הגיליון המוגנים. אם לא מוגדר תיאור, השיטה הזו מחזירה מחרוזת ריקה.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Protects the sheet and sets the description. const sampleProtectedSheet = sheet.protect().setDescription('Sample sheet is protected'); // Gets the description of the protected sheet and logs it to the console. const sampleProtectedSheetDescription = sampleProtectedSheet.getDescription(); console.log(sampleProtectedSheetDescription);
חזרה
String — תיאור הטווח או הגיליון המוגנים, או מחרוזת ריקה אם לא הוגדר תיאור.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Editors()
מחזירה את רשימת העורכים של הטווח או הגיליון המוגנים. מוצג חריג אם למשתמש אין הרשאה לערוך את הטווח או הגיליון המוגנים.
// Protect the active sheet, then remove all other users from the list of // editors. const sheet = SpreadsheetApp.getActiveSheet(); const 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 throws an exception // upon removing the group. const me = Session.getEffectiveUser(); protection.addEditor(me); protection.removeEditors(protection.getEditors()); if (protection.canDomainEdit()) { protection.setDomainEdit(false); }
חזרה
User[] — מערך של משתמשים עם הרשאה לערוך את הטווח או הגיליון המוגנים
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Protection Type()
מחזירה את סוג האזור המוגן, RANGE או SHEET.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Protects the sheet. const sampleProtectedSheet = sheet.protect(); // Gets the type of the protected area. const protectionType = sampleProtectedSheet.getProtectionType(); // Logs 'SHEET'to the console since the type of the protected area is a sheet. console.log(protectionType.toString());
חזרה
Protection — סוג האזור המוגן, RANGE או SHEET.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Range()
מחזירה את הטווח שמוגן. אם ההגנה חלה על הגיליון ולא על טווח, הפונקציה הזו מחזירה טווח שכולל את כל הגיליון.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets the range 'A1:B10' of Sheet1. const range = sheet.getRange('A1:B10'); // Makes cells A1:B10 a protected range. const sampleProtectedRange = range.protect(); // Gets the protected ranges on the sheet. const protections = sheet.getProtections(SpreadsheetApp.ProtectionType.RANGE); // Logs the A1 notation of the first protected range on the sheet. console.log(protections[0].getRange().getA1Notation());
חזרה
Range – הטווח שמוגן.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Range Name()
מחזירה את השם של טווח התאים המוגן אם הוא משויך לטווח תאים בעל שם. הפונקציה מחזירה את הערך null אם ההגנה לא משויכת לטווח בעל שם. שימו לב: סקריפטים צריכים להפעיל את set באופן מפורש כדי לשייך טווח מוגן לטווח בעל שם. הפעלת Range.protect() כדי ליצור הגנה מ-Range שהוא במקרה טווח בעל שם, בלי להפעיל את set, לא מספיקה כדי לשייך אותם. עם זאת, אם יוצרים טווח מוגן מטווח בעל שם בממשק המשתמש של Google Sheets, הם משויכים אוטומטית.
// Protect a named range in a spreadsheet and log the name of the protected // range. const ss = SpreadsheetApp.getActive(); const range = ss.getRange('A1:B10'); const protection = range.protect(); ss.setNamedRange('Test', range); // Create a named range. protection.setRangeName( 'Test'); // Associate the protection with the named range. Logger.log( protection.getRangeName()); // Verify the name of the protected range.
חזרה
String|null – השם של הטווח המוגן, או null אם הטווח המוגן לא משויך לטווח עם שם
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Target Audiences()
הפונקציה מחזירה את מזהי קהלי היעד שיכולים לערוך את הטווח המוגן.
חזרה
Target — מערך של מזהים של קהלי יעד.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Unprotected Ranges()
מחזירה מערך של טווחים לא מוגנים בגיליון מוגן. אם אובייקט Protection תואם לטווח מוגן במקום לגיליון מוגן, השיטה הזו מחזירה מערך ריק. כדי לשנות את הטווחים הלא מוגנים, משתמשים ב-set כדי להגדיר מערך חדש של טווחים. כדי להגן מחדש על הגיליון כולו, מגדירים מערך ריק.
// Unprotect cells E2:F5 in addition to any other unprotected ranges in the // protected sheet. const sheet = SpreadsheetApp.getActiveSheet(); const protection = sheet.protect(); const unprotected = protection.getUnprotectedRanges(); unprotected.push(sheet.getRange('E2:F5')); protection.setUnprotectedRanges(unprotected);
חזרה
Range[] – מערך של טווחים לא מוגנים בגיליון מוגן
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
is Warning Only()
קובעת אם האזור המוגן משתמש בהגנה מבוססת-אזהרה. הגנה שמבוססת על אזהרה
אומרת שכל משתמש יכול לערוך נתונים באזור, אבל אם הוא מנסה לערוך, מוצגת לו אזהרה שבה הוא מתבקש לאשר את העריכה. כברירת מחדל, טווחים או גיליונות מוגנים לא מבוססים על אזהרות. כדי לעבור למצב אזהרה, משתמשים בפקודה set.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Protects the sheet. const sampleProtectedSheet = sheet.protect(); // Sets the warning status for the protected sheet as true. sampleProtectedSheet.setWarningOnly(true); const protectedSheetWarningStatus = sampleProtectedSheet.isWarningOnly(); // Logs the warning status of the protected sheet to the console. console.log(protectedSheetWarningStatus);
חזרה
Boolean — true אם הטווח או הגיליון המוגנים משתמשים רק בהגנה שמבוססת על אזהרות.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
remove()
הסרת ההגנה מהטווח או מהגיליון.
// Remove all range protections in the spreadsheet that the user has permission // to edit. const ss = SpreadsheetApp.getActive(); const protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE); for (let i = 0; i < protections.length; i++) { const protection = protections[i]; if (protection.canEdit()) { protection.remove(); } }
// Remove sheet protection from the active sheet, if the user has permission to // edit it. const sheet = SpreadsheetApp.getActiveSheet(); const protection = sheet.getProtections(SpreadsheetApp.ProtectionType.SHEET)[0]; if (protection?.canEdit()) { protection.remove(); }
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
remove Editor(emailAddress)
הפונקציה מסירה את המשתמש שצוין מרשימת העורכים של הגיליון או הטווח המוגנים. שימו לב: אם המשתמש חבר בקבוצת Google שיש לה הרשאת עריכה, או אם לכל המשתמשים בדומיין יש הרשאת עריכה, המשתמש עדיין יוכל לערוך את האזור המוגן. אי אפשר להסיר את הבעלים של הגיליון האלקטרוני או את המשתמש הנוכחי.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Creates a variable for an email address. // TODO(developer): Replace the email address with a valid one. const TEST_EMAIL = 'baklavainthebalkans@gmail.com'; // Protects the sheet. const sampleProtectedSheet = sheet.protect(); // Adds an editor to the protected sheet using the email address variable. sampleProtectedSheet.addEditor(TEST_EMAIL); // Removes the editor from the protected sheet using the email address variable. sampleProtectedSheet.removeEditor(TEST_EMAIL); // Gets the editors of the protected sheet. const editors = sampleProtectedSheet.getEditors(); // Logs the editors' email addresses to the console. for (const editor of editors) { console.log(editor.getEmail()); }
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
email | String | כתובת האימייל של המשתמש שרוצים להסיר. |
חזרה
Protection – האובייקט שמייצג את הגדרות ההגנה, לשרשור.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
remove Editor(user)
הפונקציה מסירה את המשתמש שצוין מרשימת העורכים של הגיליון או הטווח המוגנים. שימו לב: אם המשתמש חבר בקבוצת Google שיש לה הרשאת עריכה, או אם לכל המשתמשים בדומיין יש הרשאת עריכה, המשתמש עדיין יוכל לערוך את האזור המוגן. אי אפשר להסיר את הבעלים של הגיליון האלקטרוני או את המשתמש הנוכחי.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Protects the sheet. const sampleProtectedSheet = sheet.protect(); // Removes the active user from the editors of the protected sheet. sampleProtectedSheet.removeEditor(Session.getActiveUser()); // Gets the editors of the protected sheet. const editors = sampleProtectedSheet.getEditors(); // Logs the editors' email addresses to the console. for (const editor of editors) { console.log(editor.getEmail()); }
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
user | User | ייצוג של המשתמש שרוצים להסיר. |
חזרה
Protection – האובייקט שמייצג את הגדרות ההגנה, לשרשור
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
remove Editors(emailAddresses)
מסירה את מערך המשתמשים שצוין מרשימת העורכים של הגיליון או הטווח המוגנים. שימו לב: אם משתמשים מסוימים הם חברים בקבוצת Google שיש לה הרשאת עריכה, או אם לכל המשתמשים בדומיין יש הרשאת עריכה, הם עדיין יוכלו לערוך את האזור המוגן. אי אפשר להסיר את הבעלים של הגיליון האלקטרוני או את המשתמש הנוכחי.
// Protect the active sheet, then remove all other users from the list of // editors. const sheet = SpreadsheetApp.getActiveSheet(); const 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 throws an exception // upon removing the group. const me = Session.getEffectiveUser(); protection.addEditor(me); protection.removeEditors(protection.getEditors()); if (protection.canDomainEdit()) { protection.setDomainEdit(false); }
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
email | String[] | מערך של כתובות אימייל של המשתמשים שרוצים להסיר. |
חזרה
Protection – האובייקט שמייצג את הגדרות ההגנה, לשרשור
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
remove Target Audience(audienceId)
מסירה את קהל היעד שצוין כבעל הרשאת עריכה בטווח התאים המוגן.
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
audience | String | המזהה של קהל היעד שרוצים להסיר. |
חזרה
Protection – האובייקט שמייצג את הגדרות ההגנה, לשרשור.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Description(description)
הגדרת התיאור של הטווח או הגיליון המוגנים.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets the sheet 'Sheet1' by its name. const sheet = ss.getSheetByName('Sheet1'); // Protects the sheet. const sampleProtectedSheet = sheet.protect(); // Sets the sheet description to 'Sheet1 is protected.' sampleProtectedSheet.setDescription('Sheet1 is protected'); // Gets the description of the protected sheet. const sampleProtectedSheetDescription = sampleProtectedSheet.getDescription(); // Logs the description of the protected sheet to the console. console.log(sampleProtectedSheetDescription);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
description | String | התיאור של הטווח או הגיליון המוגנים. |
חזרה
Protection – האובייקט שמייצג את הגדרות ההגנה, לשרשור.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Domain Edit(editable)
ההגדרה קובעת אם לכל המשתמשים בדומיין שבבעלותו הגיליון האלקטרוני יש הרשאה לערוך את הטווח או הגיליון המוגנים. שימו לב: משתמשים שיש להם הרשאת עריכה מפורשת יכולים לערוך את האזור המוגן בלי קשר להגדרה הזו. מוחזרת חריגה אם הגיליון האלקטרוני לא שייך לדומיין Google Workspace (כלומר, אם הוא בבעלות של חשבון gmail.com).
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
editable | Boolean | true אם רוצים שכל המשתמשים בדומיין שבבעלותו הגיליון האלקטרוני יוכלו לערוך את הטווח או הגיליון המוגנים; false אם לא רוצים. |
חזרה
Protection – האובייקט שמייצג את הגדרות ההגנה, לשרשור
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Named Range(namedRange)
משייך את הטווח המוגן לטווח קיים בעל שם. אם הטווח עם השם מכסה אזור שונה מהטווח המוגן הנוכחי, השיטה הזו מעבירה את ההגנה כך שתכסה את הטווח עם השם במקום זאת. הטווח עם השם חייב להיות באותו גיליון כמו הטווח המוגן הנוכחי. שימו לב: כדי לשייך טווח מוגן לטווח עם שם, צריך להפעיל את ה-method הזה באופן מפורש בסקריפט. הפעלה של Range.protect() כדי ליצור הגנה מ-Range שהוא במקרה טווח עם שם, בלי להפעיל את set, לא מספיקה כדי לשייך אותם. עם זאת, אם יוצרים טווח מוגן מתוך טווח בעל שם בממשק המשתמש של Google Sheets, הם משויכים אוטומטית.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Protects cells A1:D10 on Sheet1. const sheet = ss.getSheetByName('Sheet1'); const protectedRange = sheet.getRange('A1:D10').protect(); // Logs the current protected range, A1:D10. console.log(protectedRange.getRange().getA1Notation()); // Creates a named range for cells E1:J10 called 'NewRange.' const newRange = sheet.getRange('E1:J10'); ss.setNamedRange('NewRange', newRange); const namedRange = ss.getNamedRanges()[0]; // Updates the protected range to the named range, 'NewRange.' // This updates the protected range on Sheet1 from A1:D10 to E1:J10. protectedRange.setNamedRange(namedRange); // Logs the updated protected range to the console. console.log(protectedRange.getRange().getA1Notation());
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
named | Named | טווח התאים הקיים עם השם שאותו רוצים לשייך לטווח התאים המוגן. |
חזרה
Protection – האובייקט שמייצג את הגדרות ההגנה, לשרשור.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Range(range)
משנה את הטווח שמוגן. אם הטווח שצוין מכסה אזור שונה מהטווח המוגן הנוכחי, השיטה הזו מעבירה את ההגנה כך שתכסה את הטווח החדש.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Protects cells A1:D10 on Sheet1 of the spreadsheet. const sheet = ss.getSheetByName('Sheet1'); const protectedRange = sheet.getRange('A1:D10').protect(); // Logs the original protected range, A1:D10, to the console. console.log(protectedRange.getRange().getA1Notation()); // Gets the range E1:J10. const newRange = sheet.getRange('E1:J10'); // Updates the protected range to E1:J10. protectedRange.setRange(newRange); // Logs the updated protected range to the console. console.log(protectedRange.getRange().getA1Notation());
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
range | Range | הטווח החדש שרוצים להגן עליו מפני עריכות. |
חזרה
Protection – האובייקט שמייצג את הגדרות ההגנה, לשרשור.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Range Name(rangeName)
משייך את הטווח המוגן לטווח קיים בעל שם. אם הטווח עם השם מכסה אזור שונה מהטווח המוגן הנוכחי, השיטה הזו מעבירה את ההגנה כך שתכסה את הטווח עם השם במקום זאת. הטווח עם השם חייב להיות באותו גיליון כמו הטווח המוגן הנוכחי. שימו לב: כדי לשייך טווח מוגן לטווח עם שם, צריך להפעיל את ה-method הזה באופן מפורש בסקריפט. הפעלה של Range.protect() כדי ליצור הגנה מ-Range שהוא במקרה טווח עם שם, בלי להפעיל את set, לא מספיקה כדי לשייך אותם. עם זאת, אם יוצרים טווח מוגן מתוך טווח בעל שם בממשק המשתמש של Google Sheets, הם משויכים אוטומטית.
// Protect a named range in a spreadsheet and log the name of the protected // range. const ss = SpreadsheetApp.getActive(); const range = ss.getRange('A1:B10'); const protection = range.protect(); ss.setNamedRange('Test', range); // Create a named range. protection.setRangeName( 'Test'); // Associate the protection with the named range. Logger.log( protection.getRangeName()); // Verify the name of the protected range.
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
range | String | השם של טווח התאים בעל השם שרוצים להגן עליו. |
חזרה
Protection – האובייקט שמייצג את הגדרות ההגנה, לשרשור
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Unprotected Ranges(ranges)
הפונקציה מבטלת את ההגנה של מערך הטווחים הנתון בגיליון מוגן. הפונקציה מחזירה חריגה אם האובייקט Protection מתאים לטווח מוגן במקום לגיליון מוגן, או אם אחד מהטווחים לא נמצא בגיליון המוגן. כדי לשנות את הטווחים הלא מוגנים, מגדירים מערך חדש של טווחים. כדי להגן מחדש על הגיליון כולו, מגדירים מערך ריק.
// Protect the active sheet except B2:C5, then remove all other users from the // list of editors. const sheet = SpreadsheetApp.getActiveSheet(); const protection = sheet.protect().setDescription('Sample protected sheet'); const unprotected = sheet.getRange('B2:C5'); protection.setUnprotectedRanges([unprotected]); // Ensure the current user is an editor before removing others. Otherwise, if // the user's edit permission comes from a group, the script throws an exception // upon removing the group. const me = Session.getEffectiveUser(); protection.addEditor(me); protection.removeEditors(protection.getEditors()); if (protection.canDomainEdit()) { protection.setDomainEdit(false); }
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
ranges | Range[] | מערך של טווחים שלא יוגנו בגיליון מוגן. |
חזרה
Protection – האובייקט שמייצג את הגדרות ההגנה, לשרשור
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Warning Only(warningOnly)
מגדיר אם הטווח המוגן הזה משתמש בהגנה מבוססת-אזהרה. הגנה מבוססת-אזהרה פירושה שכל משתמש יכול לערוך נתונים באזור, אלא אם העריכה מציגה אזהרה שמבקשת מהמשתמש לאשר את העריכה. כברירת מחדל, טווחים או גיליונות מוגנים לא מבוססים על אזהרות. כדי לבדוק את מצב האזהרה, אפשר להשתמש ב-is.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets the sheet 'Sheet1' by its name. const sheet = ss.getSheetByName('Sheet1'); // Protects the sheet and sets the protection to warning-based. const sampleProtectedSheet = sheet.protect().setWarningOnly(true); // Logs whether the protected sheet is warning-based to the console. console.log(sampleProtectedSheet.isWarningOnly());
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
warning | Boolean |
חזרה
Protection – האובייקט שמייצג את הגדרות ההגנה, לשרשור.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets