Class Protection

الحماية

الوصول إلى النطاقات والأوراق المحمية وتعديلها يمكن للنطاق المحمي حماية إما النطاق الثابت نطاق من الخلايا أو نطاق مُعنوَن. قد تحتوي الورقة المحمية على مناطق غير محمية. بالنسبة جداول البيانات التي تم إنشاؤها باستخدام الإصدار القديم من "جداول بيانات Google"، يمكنك استخدام PageProtection. الفصل بدلاً من ذلك.

// Protect range A1:B10, then remove all other users from the list of editors.
var ss = SpreadsheetApp.getActive();
var range = ss.getRange('A1:B10');
var 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.
var 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.
var ss = SpreadsheetApp.getActive();
var protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE);
for (var i = 0; i < protections.length; i++) {
  var protection = protections[i];
  if (protection.canEdit()) {
    protection.remove();
  }
}
// Protect the active sheet, then remove all other users from the list of editors.
var sheet = SpreadsheetApp.getActiveSheet();
var 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.
var me = Session.getEffectiveUser();
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
  protection.setDomainEdit(false);
}

الطُرق

الطريقةنوع الإرجاعوصف قصير
addEditor(emailAddress)Protectionلإضافة المستخدم المعني إلى قائمة المحررين لورقة البيانات أو النطاق المحمي.
addEditor(user)Protectionلإضافة المستخدم المعني إلى قائمة المحررين لورقة البيانات أو النطاق المحمي.
addEditors(emailAddresses)Protectionلإضافة صفيف محدد من المستخدمين إلى قائمة المحرِّرين لورقة البيانات أو النطاق المحمي.
addTargetAudience(audienceId)Protectionيضيف الجمهور المستهدف المحدَّد كمحرِّر للنطاق المحمي.
canDomainEdit()Booleanتحدِّد هذه السياسة ما إذا كان جميع المستخدمين في النطاق الذي يملك جدول البيانات لديهم إذن بتعديله. النطاق أو الورقة المحمية.
canEdit()Booleanتحدِّد هذه السياسة ما إذا كان المستخدم لديه إذن بتعديل النطاق المحمي أو ورقة البيانات المحمية.
getDescription()Stringالحصول على وصف النطاق المحمي أو الورقة المحمية
getEditors()User[]للحصول على قائمة بالمحرّرين للنطاق المحمي أو ورقة البيانات المحمية
getProtectionType()ProtectionTypeيحدّد نوع المنطقة المحمية، إما RANGE أو SHEET.
getRange()Rangeيحصل على النطاق المحمي.
getRangeName()Stringيحصل على اسم النطاق المحمي إذا كان مرتبطًا بنطاق مُعنوَن.
getTargetAudiences()TargetAudience[]تعرض أرقام تعريف الجماهير المستهدفة التي يمكنها تعديل النطاق المحمي.
getUnprotectedRanges()Range[]يحصل على مصفوفة من النطاقات غير المحمية داخل ورقة بيانات محمية.
isWarningOnly()Booleanتحدِّد هذه السياسة ما إذا كانت المنطقة المحمية تستخدم "مستند إلى تحذير" حماية البيانات.
remove()voidإلغاء حماية النطاق أو الورقة.
removeEditor(emailAddress)Protectionلإزالة المستخدم المعني من قائمة المحررين لورقة البيانات أو النطاق المحمي.
removeEditor(user)Protectionلإزالة المستخدم المعني من قائمة المحررين لورقة البيانات أو النطاق المحمي.
removeEditors(emailAddresses)Protectionلإزالة مصفوفة معيّنة من المستخدمين من قائمة المحرِّرين لورقة البيانات أو النطاق المحمي.
removeTargetAudience(audienceId)Protectionإزالة الجمهور المستهدف المحدّد كمحرِّر للنطاق المحمي.
setDescription(description)Protectionتضبط هذه السياسة وصف النطاق المحمي أو الورقة المحمية.
setDomainEdit(editable)Protectionلضبط ما إذا كان جميع المستخدمين في النطاق الذي يمتلك جدول البيانات لديهم الإذن بتعديل ملف نطاق أو ورقة محمية.
setNamedRange(namedRange)Protectionتعمل هذه السياسة على ربط النطاق المحمي بنطاق مُعنوَن حالي.
setRange(range)Protectionيتم ضبط النطاق المحمي.
setRangeName(rangeName)Protectionتعمل هذه السياسة على ربط النطاق المحمي بنطاق مُعنوَن حالي.
setUnprotectedRanges(ranges)Protectionإلغاء حماية صفيف محدد من النطاقات داخل ورقة محمية.
setWarningOnly(warningOnly)Protectionلضبط ما إذا كان هذا النطاق المحمي يستخدم "مستند إلى تحذير" أم لا حماية البيانات.

الوثائق التفصيلية

addEditor(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());
}

المعلمات

الاسمالنوعالوصف
emailAddressStringعنوان البريد الإلكتروني للمستخدِم الذي تريد إضافته.

الإرجاع

Protection - الكائن الذي يمثل إعدادات الحماية، للتسلسل.

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addEditor(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());
}

المعلمات

الاسمالنوعالوصف
userUserتمثيل للمستخدم المطلوب إضافته

الإرجاع

Protection - الكائن الذي يمثل إعدادات الحماية، للتسلسل.

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addEditors(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());
}

المعلمات

الاسمالنوعالوصف
emailAddressesString[]مصفوفة من عناوين البريد الإلكتروني للمستخدمين المطلوب إضافتها.

الإرجاع

Protection - الكائن الذي يمثل إعدادات الحماية، للتسلسل.

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addTargetAudience(audienceId)

يضيف الجمهور المستهدف المحدَّد كمحرِّر للنطاق المحمي.

المعلمات

الاسمالنوعالوصف
audienceIdStringرقم تعريف الجمهور المستهدف المطلوب إضافته.

الإرجاع

Protection - الكائن الذي يمثل إعدادات الحماية، للتسلسل.

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

canDomainEdit()

تحدِّد هذه السياسة ما إذا كان جميع المستخدمين في النطاق الذي يملك جدول البيانات لديهم إذن بتعديله. النطاق أو الورقة المحمية. يؤدي إلى عرض استثناء إذا لم يكن لدى المستخدم إذن بالتعديل النطاق أو الورقة المحمية.

// 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());

الإرجاع

Booleantrue إذا كان جميع المستخدمين في النطاق الذي يملك جدول البيانات لديهم إذن تعديل النطاق المحمي أو الورقة المحمية؛ false إذا لم يحددوا.

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

canEdit()

تحدِّد هذه السياسة ما إذا كان المستخدم لديه إذن بتعديل النطاق المحمي أو ورقة البيانات المحمية. تشير رسالة الأشكال البيانية يستطيع مالك جدول البيانات دائمًا تعديل النطاقات والأوراق المحمية.

// Remove all range protections in the spreadsheet that the user has permission to edit.
var ss = SpreadsheetApp.getActive();
var protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE);
for (var i = 0; i < protections.length; i++) {
  var protection = protections[i];
  if (protection.canEdit()) {
    protection.remove();
  }
}

الإرجاع

Booleantrue إذا كان لدى المستخدم إذن بتعديل النطاق المحمي أو ورقة البيانات المحمية false إن لم يكن

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getDescription()

الحصول على وصف النطاق المحمي أو الورقة المحمية وفي حال عدم تحديد وصف، سيتم استخدام هذه الطريقة تُرجع سلسلة فارغة.

// 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

getEditors()

للحصول على قائمة بالمحرّرين للنطاق المحمي أو ورقة البيانات المحمية يعرض استثناءً إذا قام المستخدم بذلك ليس لديهم إذن لتعديل النطاق المحمي أو الورقة المحمية.

// Protect the active sheet, then remove all other users from the list of editors.
var sheet = SpreadsheetApp.getActiveSheet();
var 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.
var 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

getProtectionType()

يحدّد نوع المنطقة المحمية، إما 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());

الإرجاع

ProtectionType: نوع المنطقة المحمية، إما RANGE أو SHEET

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getRange()

يحصل على النطاق المحمي. إذا كانت الحماية تنطبق على ورقة البيانات بدلاً من النطاق، فإن هذه الطريقة تُرجع نطاقًا يمتد إلى الورقة بأكملها.

// 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

getRangeName()

يحصل على اسم النطاق المحمي إذا كان مرتبطًا بنطاق مُعنوَن. تعرض null إذا كانت الحماية غير مرتبطة بنطاق مُعنوَن. لاحظ أن النصوص البرمجية يجب أن استدعاء الدالة setRangeName(rangeName) لربط نطاق محمي بنطاق مُعنوَن يتصل Range.protect() لإنشاء حماية من Range الذي يصادف أنه النطاق المعنوَن، بدون استدعاء setRangeName(rangeName)، غير كافٍ لربط معهم. ومع ذلك، يؤدي إنشاء نطاق محمي من نطاق مُعنوَن في واجهة مستخدم "جداول بيانات Google" إلى الربط تلقائيًا.

// Protect a named range in a spreadsheet and log the name of the protected range.
var ss = SpreadsheetApp.getActive();
var range = ss.getRange('A1:B10');
var 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 إذا لم يكن النطاق المحمي مرتبط بنطاق مُعنوَن

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getTargetAudiences()

تعرض أرقام تعريف الجماهير المستهدفة التي يمكنها تعديل النطاق المحمي.

الإرجاع

TargetAudience[] — مصفوفة من أرقام تعريف الجماهير المستهدفة.

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getUnprotectedRanges()

يحصل على مصفوفة من النطاقات غير المحمية داخل ورقة بيانات محمية. إذا كان الكائن Protection مع نطاق محمي بدلاً من ورقة محمية، فإن هذه الطريقة تقوم بإرجاع صفيفة. لتغيير النطاقات غير المحمية، استخدِم setUnprotectedRanges(ranges) لضبط صفيفة جديدة من النطاقات؛ لإعادة حماية الورقة بأكملها، قم بتعيين صفيف فارغ.

// Unprotect cells E2:F5 in addition to any other unprotected ranges in the protected sheet.
var sheet = SpreadsheetApp.getActiveSheet();
var protection = sheet.protect();
var 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

isWarningOnly()

تحدِّد هذه السياسة ما إذا كانت المنطقة المحمية تستخدم "مستند إلى تحذير" حماية البيانات. الحماية المستندة إلى التحذير يعني أنه يمكن لكل مستخدم تعديل البيانات في المنطقة، باستثناء مطالبات التعديل، حيث يتم عرض تحذير المستخدم لتأكيد التعديل. بشكلٍ تلقائي، لا تستند النطاقات أو الأوراق المحمية إلى تحذيرات. إلى التغيير إلى حالة التحذير، استخدِم setWarningOnly(warningOnly).

// 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);

الإرجاع

Booleantrue إذا كان النطاق أو الورقة المحميان يستخدمان حماية مستندة إلى التحذير فقط.

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • 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.
var ss = SpreadsheetApp.getActive();
var protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE);
for (var i = 0; i < protections.length; i++) {
  var protection = protections[i];
  if (protection.canEdit()) {
    protection.remove();
  }
}
// Remove sheet protection from the active sheet, if the user has permission to edit it.
var sheet = SpreadsheetApp.getActiveSheet();
var protection = sheet.getProtections(SpreadsheetApp.ProtectionType.SHEET)[0];
if (protection && protection.canEdit()) {
  protection.remove();
}

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

removeEditor(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());
}

المعلمات

الاسمالنوعالوصف
emailAddressStringعنوان البريد الإلكتروني للمستخدم المطلوب إزالته.

الإرجاع

Protection - الكائن الذي يمثل إعدادات الحماية، للتسلسل.

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

removeEditor(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());
}

المعلمات

الاسمالنوعالوصف
userUserتمثيل للمستخدم المطلوب إزالته

الإرجاع

Protection: الكائن الذي يمثل إعدادات الحماية، للتسلسل

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

removeEditors(emailAddresses)

لإزالة مصفوفة معيّنة من المستخدمين من قائمة المحرِّرين لورقة البيانات أو النطاق المحمي. يُرجى ملاحظة أنّه إذا كان أي من المستخدمين عضوًا في إحدى "مجموعات Google" التي لديها إذن تعديل، أو إذا كان جميع المستخدمين يكون لدى المستخدمين في النطاق إذن تعديل، ولا يزال بإمكان هؤلاء المستخدمين تعديل الملفات المحمية واحدة. ولا يمكن إزالة مالك جدول البيانات أو المستخدم الحالي.

// Protect the active sheet, then remove all other users from the list of editors.
var sheet = SpreadsheetApp.getActiveSheet();
var 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.
var me = Session.getEffectiveUser();
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
  protection.setDomainEdit(false);
}

المعلمات

الاسمالنوعالوصف
emailAddressesString[]مصفوفة من عناوين البريد الإلكتروني للمستخدمين المطلوب إزالتها.

الإرجاع

Protection: الكائن الذي يمثل إعدادات الحماية، للتسلسل

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

removeTargetAudience(audienceId)

إزالة الجمهور المستهدف المحدّد كمحرِّر للنطاق المحمي.

المعلمات

الاسمالنوعالوصف
audienceIdStringرقم تعريف الجمهور المستهدف المطلوب إزالته.

الإرجاع

Protection - الكائن الذي يمثل إعدادات الحماية، للتسلسل.

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setDescription(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);

المعلمات

الاسمالنوعالوصف
descriptionStringوصف النطاق المحمي أو الورقة المحمية.

الإرجاع

Protection - الكائن الذي يمثل إعدادات الحماية، للتسلسل.

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setDomainEdit(editable)

لضبط ما إذا كان جميع المستخدمين في النطاق الذي يمتلك جدول البيانات لديهم الإذن بتعديل ملف نطاق أو ورقة محمية. يُرجى العِلم أنّه يمكن لأي مستخدم لديه إذن تعديل صريح تعديل المنطقة المحمية بغض النظر عن هذا الإعداد. يعرض استثناءً إذا كان جدول البيانات لا تنتمي إلى نطاق Google Workspace (أي إذا كان يملكه حساب gmail.com).

المعلمات

الاسمالنوعالوصف
editableBooleantrue إذا كان يجب أن يكون لدى جميع المستخدمين في النطاق الذي يملك جدول البيانات إذن بتعديل النطاق المحمي أو الورقة المحمية false إذا لم يكن كذلك.

الإرجاع

Protection: الكائن الذي يمثل إعدادات الحماية، للتسلسل

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setNamedRange(namedRange)

تعمل هذه السياسة على ربط النطاق المحمي بنطاق مُعنوَن حالي. إذا كان النطاق المعنوَن يغطي منطقة مختلفة عن النطاق المحمي الحالي، فإن هذه الطريقة تنقل الحماية لتغطية النطاق المسمى بدلاً من ذلك. يجب أن يكون النطاق المعنوَن على ورقة البيانات نفسها مثل نطاق الحماية الحالي. النطاق. لاحظ أن النصوص البرمجية يجب أن تستدعي هذه الطريقة بشكل صريح لربط نطاق محمي بـ نطاق مُعنوَن جارٍ الاتصال بـ Range.protect() لإنشاء حماية من Range الذي يصادف أنه نطاق مُعنوَن، بدون استدعاء setRangeName(rangeName)، ليس كافية لربطها. ومع ذلك، فإن إنشاء نطاق محمي من نطاق مُعنوَن في ويتم ربطها تلقائيًا في واجهة مستخدم "جداول بيانات 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());

المعلمات

الاسمالنوعالوصف
namedRangeNamedRangeالنطاق المُعنون الحالي المطلوب ربطه بالنطاق المحمي.

الإرجاع

Protection - الكائن الذي يمثل إعدادات الحماية، للتسلسل.

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setRange(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());

المعلمات

الاسمالنوعالوصف
rangeRangeالنطاق الجديد للحماية من التعديلات.

الإرجاع

Protection - الكائن الذي يمثل إعدادات الحماية، للتسلسل.

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setRangeName(rangeName)

تعمل هذه السياسة على ربط النطاق المحمي بنطاق مُعنوَن حالي. إذا كان النطاق المعنوَن يغطي منطقة مختلفة عن النطاق المحمي الحالي، فإن هذه الطريقة تنقل الحماية لتغطية النطاق المسمى بدلاً من ذلك. يجب أن يكون النطاق المعنوَن على ورقة البيانات نفسها مثل نطاق الحماية الحالي. النطاق. لاحظ أن النصوص البرمجية يجب أن تستدعي هذه الطريقة بشكل صريح لربط نطاق محمي بـ نطاق مُعنوَن جارٍ الاتصال بـ Range.protect() لإنشاء حماية من Range الذي يصادف أنه نطاق مُعنوَن، بدون استدعاء setRangeName(rangeName)، ليس كافية لربطها. ومع ذلك، فإن إنشاء نطاق محمي من نطاق مُعنوَن في ويتم ربطها تلقائيًا في واجهة مستخدم "جداول بيانات Google".

// Protect a named range in a spreadsheet and log the name of the protected range.
var ss = SpreadsheetApp.getActive();
var range = ss.getRange('A1:B10');
var 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.

المعلمات

الاسمالنوعالوصف
rangeNameStringاسم النطاق المُعنون المطلوب حمايته.

الإرجاع

Protection: الكائن الذي يمثل إعدادات الحماية، للتسلسل

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setUnprotectedRanges(ranges)

إلغاء حماية صفيف محدد من النطاقات داخل ورقة محمية. يطرح استثناء إذا كان يتوافق كائن Protection مع نطاق محمي بدلاً من ورقة محمية أو إذا أي من النطاقات ليست في ورقة البيانات المحمية. لتغيير النطاقات غير المحمية، يمكنك إعداد نطاق مصفوفة النطاقات؛ لإعادة حماية الورقة بأكملها، قم بتعيين صفيف فارغ.

// Protect the active sheet except B2:C5, then remove all other users from the list of editors.
var sheet = SpreadsheetApp.getActiveSheet();
var protection = sheet.protect().setDescription('Sample protected sheet');
var 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.
var me = Session.getEffectiveUser();
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
  protection.setDomainEdit(false);
}

المعلمات

الاسمالنوعالوصف
rangesRange[]مصفوفة النطاقات المراد تركها بدون حماية داخل ورقة محمية.

الإرجاع

Protection: الكائن الذي يمثل إعدادات الحماية، للتسلسل

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setWarningOnly(warningOnly)

لضبط ما إذا كان هذا النطاق المحمي يستخدم "مستند إلى تحذير" أم لا حماية البيانات. مستندة إلى التحذير تعني أنه يمكن لكل مستخدم تعديل البيانات في المنطقة، باستثناء مطالبات تعديل تظهر بها رسالة تحذيرية وتطلب من المستخدم تأكيد التعديل. لا يتم تلقائيًا تصنيف النطاقات أو الأوراق المحمية يستند إلى التحذيرات. للتأكّد من حالة التحذير، استخدِم isWarningOnly().

// 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());

المعلمات

الاسمالنوعالوصف
warningOnlyBoolean

الإرجاع

Protection - الكائن الذي يمثل إعدادات الحماية، للتسلسل.

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة إذنًا باستخدام واحد أو أكثر من النطاقات التالية:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets