Class Protection

Koruma

Korunan aralıklara ve sayfalara erişip bunları değiştirin. Korunan bir aralık, statik bir hücre aralığını veya adlandırılmış aralığı koruyabilir. Korunan bir sayfa, korumasız bölgeler içerebilir. Google E-Tablolar'ın eski sürümüyle oluşturulmuş e-tablolar için PageProtection sınıfını kullanın.

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

Yöntemler

YöntemDönüş türüKısa açıklama
addEditor(emailAddress)ProtectionBelirli bir kullanıcıyı, korunan sayfa veya aralık için düzenleyen listesine ekler.
addEditor(user)ProtectionBelirli bir kullanıcıyı, korunan sayfa veya aralık için düzenleyen listesine ekler.
addEditors(emailAddresses)ProtectionBelirtilen kullanıcı dizisini, korunan sayfa veya aralık için düzenleyen listesine ekler.
addTargetAudience(audienceId)ProtectionBelirtilen hedef kitleyi, korunan aralığın düzenleyeni olarak ekler.
canDomainEdit()BooleanE-tablonun sahibi olan alandaki tüm kullanıcıların, korunan aralığı veya sayfayı düzenleme iznine sahip olup olmadığını belirler.
canEdit()BooleanKullanıcının korunan aralığı veya sayfayı düzenleme izni olup olmadığını belirler.
getDescription()StringKorunan aralığın veya sayfanın açıklamasını alır.
getEditors()User[]Korunan aralık veya sayfa için düzenleyenlerin listesini alır.
getProtectionType()ProtectionTypeKorunan alanın türünü (RANGE veya SHEET) alır.
getRange()RangeKorunan aralığı alır.
getRangeName()StringKorunan aralığın adlandırılmış bir aralıkla ilişkilendirilmesi durumunda bu aralığın adını alır.
getTargetAudiences()TargetAudience[]Korunan aralığı düzenleyebilen hedef kitlelerin kimliklerini döndürür.
getUnprotectedRanges()Range[]Korunan bir sayfadaki korumasız aralık dizisini alır.
isWarningOnly()BooleanKorunan alanda "uyarıya dayalı" koruma kullanılıp kullanılmadığını belirler.
remove()voidAralığın veya sayfanın korumasını kaldırır.
removeEditor(emailAddress)ProtectionBelirli bir kullanıcıyı, korunan sayfa veya aralık için düzenleyenler listesinden kaldırır.
removeEditor(user)ProtectionBelirli bir kullanıcıyı, korunan sayfa veya aralık için düzenleyenler listesinden kaldırır.
removeEditors(emailAddresses)ProtectionBelirtilen kullanıcı dizisini, korunan sayfa veya aralık için düzenleyen listesinden kaldırır.
removeTargetAudience(audienceId)ProtectionBelirtilen hedef kitleyi, korunan aralığın düzenleyeni olarak kaldırır.
setDescription(description)ProtectionKorunan aralığın veya sayfanın açıklamasını ayarlar.
setDomainEdit(editable)ProtectionE-tablonun sahibi olan alandaki tüm kullanıcıların, korunan aralığı veya sayfayı düzenleme iznine sahip olup olmadığını belirler.
setNamedRange(namedRange)ProtectionKorunan aralığı mevcut bir adlandırılmış aralıkla ilişkilendirir.
setRange(range)ProtectionKorunan aralığı ayarlar.
setRangeName(rangeName)ProtectionKorunan aralığı mevcut bir adlandırılmış aralıkla ilişkilendirir.
setUnprotectedRanges(ranges)ProtectionKorunan bir sayfadaki belirli aralık dizisinin korumasını kaldırır.
setWarningOnly(warningOnly)ProtectionBu korumalı aralığın "uyarıya dayalı" koruma kullanıp kullanmayacağını belirler.

Ayrıntılı belgeler

addEditor(emailAddress)

Belirli bir kullanıcıyı, korunan sayfa veya aralık için düzenleyen listesine ekler. Bu yöntem, kullanıcıya e-tablonun kendisini düzenlemesi için otomatik olarak izin vermez. Bunu da yapmak için Spreadsheet.addEditor(emailAddress) yöntemini çağırın.

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

Parametreler

AdTürAçıklama
emailAddressStringEklenecek kullanıcının e-posta adresi.

Return

Protection: Zincirleme için koruma ayarlarını temsil eden nesne.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

addEditor(user)

Belirli bir kullanıcıyı, korunan sayfa veya aralık için düzenleyen listesine ekler. Bu yöntem, kullanıcıya e-tablonun kendisini düzenlemesi için otomatik olarak izin vermez. Bunu da yapmak için Spreadsheet.addEditor(user) yöntemini çağırın.

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

Parametreler

AdTürAçıklama
userUserEklenecek kullanıcının temsili.

Return

Protection: Zincirleme için koruma ayarlarını temsil eden nesne.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

addEditors(emailAddresses)

Belirtilen kullanıcı dizisini, korunan sayfa veya aralık için düzenleyen listesine ekler. Bu yöntem, kullanıcılara otomatik olarak e-tabloyu düzenleme izni vermez. Bunu yapmak için de Spreadsheet.addEditors(emailAddresses) yöntemini çağırın.

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

Parametreler

AdTürAçıklama
emailAddressesString[]Eklenecek kullanıcıların e-posta adresleri dizisi.

Return

Protection: Zincirleme için koruma ayarlarını temsil eden nesne.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

addTargetAudience(audienceId)

Belirtilen hedef kitleyi, korunan aralığın düzenleyeni olarak ekler.

Parametreler

AdTürAçıklama
audienceIdStringEklenecek hedef kitlenin kimliği.

Return

Protection: Zincirleme için koruma ayarlarını temsil eden nesne.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

canDomainEdit()

E-tablonun sahibi olan alandaki tüm kullanıcıların, korunan aralığı veya sayfayı düzenleme iznine sahip olup olmadığını belirler. Kullanıcının korunan aralığı veya sayfayı düzenleme izni yoksa bir istisna oluşturur.

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

Return

Boolean — E-tablonun sahibi alandaki tüm kullanıcıların korunan aralığı veya sayfayı düzenleme izni varsa true; bu izin yoksa false.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

canEdit()

Kullanıcının korunan aralığı veya sayfayı düzenleme izni olup olmadığını belirler. E-tablo sahibi, korunan aralıkları ve sayfaları her zaman düzenleyebilir.

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

Return

Boolean — Kullanıcının korunan aralığı veya sayfayı düzenleme izni varsa true; yoksa false

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

getDescription()

Korunan aralığın veya sayfanın açıklamasını alır. Herhangi bir açıklama ayarlanmazsa bu yöntem boş bir dize döndürür.

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

Return

String: Korunan aralığın veya sayfanın açıklaması ya da açıklama ayarlanmamışsa boş bir dize.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

getEditors()

Korunan aralık veya sayfa için düzenleyenlerin listesini alır. Kullanıcının korunan aralığı veya sayfayı düzenleme izni yoksa bir istisna oluşturur.

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

Return

User[]: Korunan aralığı veya sayfayı düzenleme izni olan kullanıcı dizisi

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

getProtectionType()

Korunan alanın türünü (RANGE veya SHEET) alır.

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

Return

ProtectionType: Korunan alanın türü (RANGE veya SHEET).

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

getRange()

Korunan aralığı alır. Koruma, aralık yerine sayfaya uygulanırsa bu yöntem tüm sayfayı kapsayan bir aralık döndürür.

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

Return

Range: Korunan aralık.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

getRangeName()

Korunan aralığın adlandırılmış bir aralıkla ilişkilendirilmesi durumunda bu aralığın adını alır. Koruma, adlandırılmış bir aralıkla ilişkilendirilmemişse null değerini döndürür. Komut dosyalarının, korunan bir aralığı adlandırılmış bir aralıkla ilişkilendirmek için açık bir şekilde setRangeName(rangeName) çağırması gerektiğini unutmayın. setRangeName(rangeName) çağrısı yapılmadan, adlandırılmış bir aralık olan Range değerine karşı koruma oluşturmak için Range.protect() çağırmak, bunların ilişkilendirilmesi için yeterli değildir. Ancak, Google E-Tablolar kullanıcı arayüzünde adlandırılmış bir aralıktan korunan bir aralık oluşturulduğunda bu aralıklar otomatik olarak ilişkilendirilir.

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

Return

String: Korunan adlandırılmış aralığın adı veya korunan aralık adlandırılmış bir aralıkla ilişkilendirilmemişse null

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

getTargetAudiences()

Korunan aralığı düzenleyebilen hedef kitlelerin kimliklerini döndürür.

Return

TargetAudience[]: Hedef kitlelerin kimlikleri dizisi.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

getUnprotectedRanges()

Korunan bir sayfadaki korumasız aralık dizisini alır. Protection nesnesi, korunan bir sayfa yerine korunan bir aralığa karşılık geliyorsa bu yöntem boş bir dizi döndürür. Korunmayan aralıkları değiştirmek için setUnprotectedRanges(ranges) kullanarak yeni bir aralık dizisi ayarlayın; sayfanın tamamını yeniden korumak için boş bir dizi ayarlayın.

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

Return

Range[]: Korunan bir sayfadaki korumasız aralıklar dizisi

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

isWarningOnly()

Korunan alanda "uyarıya dayalı" koruma kullanılıp kullanılmadığını belirler. Uyarıya dayalı koruma, her kullanıcının alandaki verileri düzenleyebileceği anlamına gelir. Tek fark düzenlemeyle ilgili olarak kullanıcıdan düzenlemeyi onaylamasını isteyen bir uyarı verir. Varsayılan olarak, korunan aralıklar veya sayfalar uyarıya dayalı değildir. Uyarı durumunu değiştirmek için setWarningOnly(warningOnly) değerini kullanın.

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

Return

Boolean — Korunan aralık veya sayfa yalnızca uyarıya dayalı koruma kullanıyorsa true.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

remove()

Aralığın veya sayfanın korumasını kaldırır.

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

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

removeEditor(emailAddress)

Belirli bir kullanıcıyı, korunan sayfa veya aralık için düzenleyenler listesinden kaldırır. Düzenleme iznine sahip bir Google Grubunun üyesi olması veya alandaki tüm kullanıcıların düzenleme iznine sahip olması durumunda koruma altındaki alanı düzenleyebileceklerini hatırlatmak isteriz. E-tablonun sahibi veya mevcut kullanıcı kaldırılamaz.

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

Parametreler

AdTürAçıklama
emailAddressStringKaldırılacak kullanıcının e-posta adresi.

Return

Protection: Zincirleme için koruma ayarlarını temsil eden nesne.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

removeEditor(user)

Belirli bir kullanıcıyı, korunan sayfa veya aralık için düzenleyenler listesinden kaldırır. Düzenleme iznine sahip bir Google Grubunun üyesi olması veya alandaki tüm kullanıcıların düzenleme iznine sahip olması durumunda koruma altındaki alanı da düzenleyebileceğini hatırlatmak isteriz. E-tablonun sahibi veya mevcut kullanıcı kaldırılamaz.

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

Parametreler

AdTürAçıklama
userUserKaldırılacak kullanıcının temsili.

Return

Protection: Zincirleme için koruma ayarlarını temsil eden nesne

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

removeEditors(emailAddresses)

Belirtilen kullanıcı dizisini, korunan sayfa veya aralık için düzenleyen listesinden kaldırır. Kullanıcılardan biri, düzenleme iznine sahip bir Google Grubu'nun üyesiyse veya alandaki tüm kullanıcıların düzenleme iznine sahip olması durumunda bu kullanıcıların korunan alanı düzenlemeye devam edebileceğini unutmayın. E-tablonun sahibi veya geçerli kullanıcı kaldırılamaz.

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

Parametreler

AdTürAçıklama
emailAddressesString[]Kaldırılacak kullanıcıların e-posta adresleri dizisi.

Return

Protection: Zincirleme için koruma ayarlarını temsil eden nesne

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

removeTargetAudience(audienceId)

Belirtilen hedef kitleyi, korunan aralığın düzenleyeni olarak kaldırır.

Parametreler

AdTürAçıklama
audienceIdStringKaldırılacak hedef kitlenin kimliği.

Return

Protection: Zincirleme için koruma ayarlarını temsil eden nesne.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

setDescription(description)

Korunan aralığın veya sayfanın açıklamasını ayarlar.

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

Parametreler

AdTürAçıklama
descriptionStringKorunan aralığın veya sayfanın açıklaması.

Return

Protection: Zincirleme için koruma ayarlarını temsil eden nesne.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

setDomainEdit(editable)

E-tablonun sahibi olan alandaki tüm kullanıcıların, korunan aralığı veya sayfayı düzenleme iznine sahip olup olmadığını belirler. Açık düzenleme iznine sahip tüm kullanıcıların, bu ayardan bağımsız olarak korumalı alanı düzenleyebileceğini unutmayın. E-tablo bir Google Workspace alanına ait değilse (yani bir gmail.com hesabına aitse) istisna oluşturur.

Parametreler

AdTürAçıklama
editableBooleanE-tablonun sahibi olan alandaki tüm kullanıcıların korunan aralığı veya sayfayı düzenleme izni olması gerekiyorsa true; bu mümkün değilse false.

Return

Protection: Zincirleme için koruma ayarlarını temsil eden nesne

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

setNamedRange(namedRange)

Korunan aralığı mevcut bir adlandırılmış aralıkla ilişkilendirir. Adlandırılmış aralık, korunan mevcut aralıktan farklı bir alanı kapsıyorsa bu yöntem, korumayı bunun yerine adlandırılmış aralığı kapsayacak şekilde taşır. Adlandırılan aralık, geçerli korunan aralıkla aynı sayfada olmalıdır. Komut dosyalarının, korunan bir aralığı adlandırılmış bir aralıkla ilişkilendirmek için bu yöntemi açıkça çağırması gerektiğini unutmayın. Adlandırılmış aralık olan bir Range'dan koruma oluşturmak için setRangeName(rangeName) yöntemini çağırmak, bunları ilişkilendirmek için yeterli değildir.Range.protect() Ancak, Google E-Tablolar kullanıcı arayüzünde adlandırılmış bir aralıktan korumalı aralık oluşturulduğunda bu aralıklar otomatik olarak ilişkilendirilir.

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

Parametreler

AdTürAçıklama
namedRangeNamedRangeKorunan aralıkla ilişkilendirilecek mevcut adlandırılmış aralık.

Return

Protection: Zincirleme için koruma ayarlarını temsil eden nesne.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

setRange(range)

Korunan aralığı ayarlar. Belirtilen aralık, korunan mevcut aralıktan farklı bir alanı kapsıyorsa bu yöntem, korumayı bunun yerine yeni aralığı kapsayacak şekilde taşır.

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

Parametreler

AdTürAçıklama
rangeRangeDüzenlemelerden korunacak yeni aralık.

Return

Protection: Zincirleme için koruma ayarlarını temsil eden nesne.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

setRangeName(rangeName)

Korunan aralığı mevcut bir adlandırılmış aralıkla ilişkilendirir. Adlandırılmış aralık, korunan mevcut aralıktan farklı bir alanı kapsıyorsa bu yöntem, korumayı bunun yerine adlandırılmış aralığı kapsayacak şekilde taşır. Adlandırılan aralık, geçerli korunan aralıkla aynı sayfada olmalıdır. Komut dosyalarının, korunan bir aralığı adlandırılmış bir aralıkla ilişkilendirmek için bu yöntemi açıkça çağırması gerektiğini unutmayın. Adlandırılmış aralık olan bir Range'dan koruma oluşturmak için setRangeName(rangeName) yöntemini çağırmak, bunları ilişkilendirmek için yeterli değildir.Range.protect() Ancak, Google E-Tablolar kullanıcı arayüzünde adlandırılmış bir aralıktan korumalı aralık oluşturulduğunda bu aralıklar otomatik olarak ilişkilendirilir.

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

Parametreler

AdTürAçıklama
rangeNameStringKorunacak adlandırılmış aralığın adı.

Return

Protection: Zincirleme için koruma ayarlarını temsil eden nesne

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

setUnprotectedRanges(ranges)

Korunan bir sayfadaki belirli aralık dizisinin korumasını kaldırır. Protection nesnesi, korunan bir sayfa yerine korunan bir aralığa karşılık geliyorsa veya aralıklardan herhangi biri korunan sayfada yer almıyorsa bir istisna atar. Korunmayan aralıkları değiştirmek için yeni bir aralık dizisi; sayfanın tamamını yeniden korumak için boş bir dizi ayarlayın.

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

Parametreler

AdTürAçıklama
rangesRange[]Korunan bir sayfada korumasız bırakılacak aralık dizisi.

Return

Protection: Zincirleme için koruma ayarlarını temsil eden nesne

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

setWarningOnly(warningOnly)

Bu korumalı aralığın "uyarıya dayalı" koruma kullanıp kullanmayacağını belirler. Uyarıya dayalı koruma, her kullanıcının bölgedeki verileri düzenleyebileceği anlamına gelir. Ancak düzenleme, kullanıcıdan düzenlemeyi onaylamasını isteyen bir uyarı verir. Varsayılan olarak, korunan aralıklar veya sayfalar uyarıya dayalı değildir. Uyarı durumunu kontrol etmek için isWarningOnly() işlevini kullanın.

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

Parametreler

AdTürAçıklama
warningOnlyBoolean

Return

Protection: Zincirleme için koruma ayarlarını temsil eden nesne.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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