الوصول إلى النطاقات وأوراق البيانات المحمية وتعديلها يمكن أن يحمي النطاق المحمي نطاقًا ثابتًا من الخلايا أو نطاقًا مُعنوَنًا. قد تتضمّن ورقة محمية مناطق غير محمية. بالنسبة إلى جداول البيانات التي تم إنشاؤها باستخدام الإصدار القديم من "جداول بيانات Google"، استخدِم فئة بدلاً من ذلك.
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); }
الطُرق
| الطريقة | نوع القيمة التي يتم إرجاعها | وصف قصير |
|---|---|---|
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" إلى ربطهما تلقائيًا.
// 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)
يربط النطاق المحمي بنطاق مسمّى حالي. إذا كان النطاق المسمّى يغطي مساحة مختلفة عن النطاق المحمي الحالي، تنقل هذه الطريقة الحماية لتغطية النطاق المسمّى بدلاً من ذلك. يجب أن يكون النطاق المسمّى في ورقة البيانات نفسها التي يتوفّر فيها النطاق المحمي الحالي. يُرجى العِلم أنّه يجب أن تستدعي البرامج النصية هذه الطريقة بشكل صريح لربط نطاق محمي بنطاق مسمّى، لأنّ استدعاء Range.protect() لإنشاء حماية من Range الذي يكون نطاقًا مسمّى، بدون استدعاء set، لا يكفي لربطهما. ومع ذلك، يؤدي إنشاء نطاق محمي من نطاق مسمّى في واجهة مستخدم "جداول بيانات 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', ); // 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)
يربط النطاق المحمي بنطاق مسمّى حالي. إذا كان النطاق المسمّى يغطي مساحة مختلفة عن النطاق المحمي الحالي، تنقل هذه الطريقة الحماية لتغطية النطاق المسمّى بدلاً من ذلك. يجب أن يكون النطاق المسمّى في ورقة البيانات نفسها التي يتوفّر فيها النطاق المحمي الحالي. يُرجى العِلم أنّه يجب أن تستدعي البرامج النصية هذه الطريقة بشكل صريح لربط نطاق محمي بنطاق مسمّى، لأنّ استدعاء Range.protect() لإنشاء حماية من Range الذي يكون نطاقًا مسمّى، بدون استدعاء set، لا يكفي لربطهما. ومع ذلك، يؤدي إنشاء نطاق محمي من نطاق مسمّى في واجهة مستخدم "جداول بيانات Google" إلى ربطهما تلقائيًا.
// 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