Class Protection

Ochrona

Dostęp do chronionych zakresów i arkuszy oraz ich modyfikowanie. Chroniony zakres może chronić statyczny zakres komórek lub zakres nazwany. Chroniony arkusz może zawierać regiony niechronione. W przypadku arkuszy kalkulacyjnych utworzonych w starszej wersji Arkuszy Google użyj klasy 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);
}

Metody

MetodaZwracany typKrótki opis
addEditor(emailAddress)ProtectionDodaje danego użytkownika do listy edytorów dla chronionego arkusza lub zakresu.
addEditor(user)ProtectionDodaje danego użytkownika do listy edytorów dla chronionego arkusza lub zakresu.
addEditors(emailAddresses)ProtectionDodaje podaną tablicę użytkowników do listy edytorów dla chronionego arkusza lub zakresu.
addTargetAudience(audienceId)ProtectionDodaje wskazaną grupę odbiorców jako edytującego zakres chroniony.
canDomainEdit()BooleanOkreśla, czy wszyscy użytkownicy w domenie, do której należy arkusz kalkulacyjny, mają uprawnienia do edytowania chronionego zakresu lub arkusza.
canEdit()BooleanOkreśla, czy użytkownik ma uprawnienia do edytowania chronionego zakresu lub arkusza.
getDescription()StringPobiera opis chronionego zakresu lub arkusza.
getEditors()User[]Pobiera listę edytorów dla chronionego zakresu lub arkusza.
getProtectionType()ProtectionTypePobiera typ obszaru chronionego: RANGE lub SHEET.
getRange()RangePobiera zakres chroniony.
getRangeName()StringPobiera nazwę zakresu chronionego, jeśli jest on powiązany z nazwanym zakresem.
getTargetAudiences()TargetAudience[]Zwraca identyfikatory grup odbiorców, które mogą edytować zakres chroniony.
getUnprotectedRanges()Range[]Pobiera tablicę niezabezpieczonych zakresów w chronionym arkuszu.
isWarningOnly()BooleanOkreśla, czy obszar chroniony jest objęty ochroną „ostrzegającą”.
remove()voidZabezpiecza zakres lub arkusz.
removeEditor(emailAddress)ProtectionUsunięcie danego użytkownika z listy edytorów dla chronionego arkusza lub zakresu
removeEditor(user)ProtectionUsunięcie danego użytkownika z listy edytorów dla chronionego arkusza lub zakresu
removeEditors(emailAddresses)ProtectionUsuwa określoną tablicę użytkowników z listy edytorów dla chronionego arkusza lub zakresu.
removeTargetAudience(audienceId)ProtectionUsuwa określoną grupę odbiorców jako edytującego zakres chroniony.
setDescription(description)ProtectionUstawia opis chronionego zakresu lub arkusza.
setDomainEdit(editable)ProtectionOkreśla, czy wszyscy użytkownicy w domenie, do której należy arkusz kalkulacyjny, mają uprawnienia do edytowania chronionego zakresu lub arkusza.
setNamedRange(namedRange)ProtectionPowiąże zakres chroniony z istniejącym zakresem nazwanym.
setRange(range)ProtectionDostosowuje zakres chroniony.
setRangeName(rangeName)ProtectionPowiąże zakres chroniony z istniejącym zakresem nazwanym.
setUnprotectedRanges(ranges)ProtectionZabezpiecza podaną tablicę zakresów w chronionym arkuszu.
setWarningOnly(warningOnly)ProtectionOkreśla, czy ten chroniony zakres korzysta z zabezpieczenia „ostrzegającego”.

Szczegółowa dokumentacja

addEditor(emailAddress)

Dodaje danego użytkownika do listy edytorów dla chronionego arkusza lub zakresu. Ta metoda nie powoduje automatycznego przyznania użytkownikowi uprawnień do edycji samego arkusza kalkulacyjnego. W tym celu wywołaj 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());
}

Parametry

NazwaTypOpis
emailAddressStringAdres e-mail użytkownika, którego chcesz dodać.

Powrót

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcucha.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

addEditor(user)

Dodaje danego użytkownika do listy edytorów dla chronionego arkusza lub zakresu. Ta metoda nie powoduje automatycznego przyznania użytkownikowi uprawnień do edycji samego arkusza kalkulacyjnego. W tym celu wywołaj 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());
}

Parametry

NazwaTypOpis
userUserReprezentacja użytkownika do dodania.

Powrót

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcucha.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

addEditors(emailAddresses)

Dodaje podaną tablicę użytkowników do listy edytorów dla chronionego arkusza lub zakresu. Ta metoda nie przyznaje użytkownikom automatycznie uprawnień do edytowania samego arkusza kalkulacyjnego. W tym celu musisz wywołać 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());
}

Parametry

NazwaTypOpis
emailAddressesString[]Tablica adresów e-mail użytkowników do dodania.

Powrót

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcucha.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

addTargetAudience(audienceId)

Dodaje wskazaną grupę odbiorców jako edytującego zakres chroniony.

Parametry

NazwaTypOpis
audienceIdStringIdentyfikator grupy odbiorców, którą chcesz dodać.

Powrót

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcucha.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

canDomainEdit()

Określa, czy wszyscy użytkownicy w domenie, do której należy arkusz kalkulacyjny, mają uprawnienia do edytowania chronionego zakresu lub arkusza. Wyjątek, jeśli użytkownik nie ma uprawnień do edytowania zakresu lub arkusza chronionego.

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

Powrót

Booleantrue, jeśli wszyscy użytkownicy w domenie, do której należy arkusz kalkulacyjny, mają uprawnienia do edytowania chronionego zakresu lub arkusza; false, jeśli nie.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

canEdit()

Określa, czy użytkownik ma uprawnienia do edytowania chronionego zakresu lub arkusza. Właściciel arkusza kalkulacyjnego może zawsze edytować chronione zakresy i arkusze.

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

Powrót

Booleantrue, jeśli użytkownik ma uprawnienia do edytowania chronionego zakresu lub arkusza; false – jeśli nie

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

getDescription()

Pobiera opis chronionego zakresu lub arkusza. Jeśli nie ustawisz opisu, ta metoda zwróci pusty ciąg.

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

Powrót

String – opis chronionego zakresu lub arkusza albo pusty ciąg, jeśli nie ma ustawionego tekstu reklamy.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

getEditors()

Pobiera listę edytorów dla chronionego zakresu lub arkusza. Wyjątek, jeśli użytkownik nie ma uprawnień do edytowania zakresu lub arkusza chronionego.

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

Powrót

User[] – tablica użytkowników z uprawnieniami do edytowania chronionego zakresu lub arkusza.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

getProtectionType()

Pobiera typ obszaru chronionego: RANGE lub 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());

Powrót

ProtectionType – typ obszaru chronionego (RANGE lub SHEET).

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

getRange()

Pobiera zakres chroniony. Jeśli zabezpieczenie jest stosowane do arkusza, a nie do zakresu, ta metoda zwraca zakres obejmujący cały arkusz.

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

Powrót

Range – zakres chroniony.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

getRangeName()

Pobiera nazwę zakresu chronionego, jeśli jest on powiązany z nazwanym zakresem. Zwraca wartość null, jeśli zabezpieczenie nie jest powiązane z zakresem nazwanym. Pamiętaj, że skrypty muszą jawnie wywoływać metodę setRangeName(rangeName), aby wiązać zakres chroniony z nazwanym zakresem. Wywołanie metody Range.protect() w celu utworzenia zabezpieczenia z elementu Range, który jest nazwany zakresem, ale bez wywołania setRangeName(rangeName), nie wystarcza, aby powiązać go z tym zakresem. Jednak utworzenie zakresu chronionego na podstawie nazwanego zakresu w interfejsie Arkuszy Google powoduje automatyczne powiązanie.

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

Powrót

String – nazwa chronionego zakresu nazwanego lub null, jeśli zakres chroniony nie jest powiązany z nazwanym zakresem.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

getTargetAudiences()

Zwraca identyfikatory grup odbiorców, które mogą edytować zakres chroniony.

Powrót

TargetAudience[] – tablica identyfikatorów odbiorców docelowych.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

getUnprotectedRanges()

Pobiera tablicę niezabezpieczonych zakresów w chronionym arkuszu. Jeśli obiekt Protection odpowiada zakresowi chronionemu, a nie zabezpieczonemu arkuszowi, ta metoda zwraca pusty tablica. Aby zmienić niechronione zakresy, użyj setUnprotectedRanges(ranges) do ustawienia nowej tablicy zakresów. Aby ponownie zabezpieczyć cały arkusz, ustaw pustą tablicę.

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

Powrót

Range[] – tablica niezabezpieczonych zakresów w chronionym arkuszu

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

isWarningOnly()

Określa, czy obszar chroniony jest objęty ochroną „ostrzegającą”. Ochrona oparta na ostrzeżeniach oznacza, że każdy użytkownik może edytować dane w danym obszarze. Wyjątkiem jest edytowanie, które wymaga ostrzeżenia z prośbą o potwierdzenie zmiany. Domyślnie chronione zakresy i arkusze nie są oparte na ostrzeżeniach. Aby zmienić stan ostrzeżenia, użyj 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);

Powrót

Booleantrue, jeśli chroniony zakres lub arkusz używa tylko zabezpieczenia opartego na ostrzeżeniach.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

remove()

Zabezpiecza zakres lub arkusz.

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

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

removeEditor(emailAddress)

Usunięcie danego użytkownika z listy edytorów dla chronionego arkusza lub zakresu Pamiętaj, że jeśli użytkownik należy do grupy dyskusyjnej Google, która ma uprawnienia do edycji, lub jeśli wszyscy użytkownicy w domenie mają uprawnienia do edycji, nadal mogą edytować obszar chroniony. Nie można usunąć właściciela arkusza kalkulacyjnego ani bieżącego użytkownika.

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

Parametry

NazwaTypOpis
emailAddressStringAdres e-mail użytkownika, którego chcesz usunąć.

Powrót

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcucha.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

removeEditor(user)

Usunięcie danego użytkownika z listy edytorów dla chronionego arkusza lub zakresu Pamiętaj, że jeśli użytkownik należy do grupy dyskusyjnej Google, która ma uprawnienia do edycji, lub wszyscy użytkownicy w domenie mają uprawnienia do edycji, nadal mogą edytować obszar chroniony. Nie można usunąć właściciela arkusza kalkulacyjnego ani bieżącego użytkownika.

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

Parametry

NazwaTypOpis
userUserReprezentacja użytkownika do usunięcia.

Powrót

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcucha.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

removeEditors(emailAddresses)

Usuwa określoną tablicę użytkowników z listy edytorów dla chronionego arkusza lub zakresu. Pamiętaj, że jeśli któryś z użytkowników należy do grupy dyskusyjnej Google, która ma uprawnienia do edycji, lub jeśli wszyscy użytkownicy w domenie mają uprawnienia do edycji, nadal mogą edytować obszar chroniony. Nie można usunąć właściciela arkusza kalkulacyjnego ani bieżącego użytkownika.

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

Parametry

NazwaTypOpis
emailAddressesString[]Tablica adresów e-mail użytkowników do usunięcia.

Powrót

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcucha.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

removeTargetAudience(audienceId)

Usuwa określoną grupę odbiorców jako edytującego zakres chroniony.

Parametry

NazwaTypOpis
audienceIdStringIdentyfikator grupy odbiorców do usunięcia.

Powrót

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcucha.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

setDescription(description)

Ustawia opis chronionego zakresu lub arkusza.

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

Parametry

NazwaTypOpis
descriptionStringOpis chronionego zakresu lub arkusza.

Powrót

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcucha.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

setDomainEdit(editable)

Określa, czy wszyscy użytkownicy w domenie, do której należy arkusz kalkulacyjny, mają uprawnienia do edytowania chronionego zakresu lub arkusza. Pamiętaj, że każdy użytkownik, który ma wyraźne uprawnienia do edycji, może edytować obszar chroniony niezależnie od tego ustawienia. Wyjątek, jeśli arkusz kalkulacyjny nie należy do domeny Google Workspace (tzn. należy do konta gmail.com).

Parametry

NazwaTypOpis
editableBooleantrue, jeśli wszyscy użytkownicy w domenie, do której należy arkusz kalkulacyjny, powinni mieć uprawnienia do edytowania chronionego zakresu lub arkusza. false, jeśli nie.

Powrót

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcucha.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

setNamedRange(namedRange)

Powiąże zakres chroniony z istniejącym zakresem nazwanym. Jeśli zakres nazwany obejmuje inny obszar niż bieżący zakres chroniony, ta metoda powoduje zastąpienie zabezpieczenia w zakresie nazwanym. Zakres nazwany musi się znajdować w tym samym arkuszu co bieżący zakres chroniony. Pamiętaj, że skrypty muszą jawnie wywoływać tę metodę w zakresie nazwanym. Wywołanie Range.protect() w celu utworzenia zabezpieczenia typu Range, które jest zakresem nazwanym, bez wywoływania funkcji setRangeName(rangeName), nie wystarcza. Jednak utworzenie zakresu chronionego na podstawie nazwanego zakresu w interfejsie Arkuszy Google spowoduje automatyczne powiązanie.

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

Parametry

NazwaTypOpis
namedRangeNamedRangeIstniejący zakres nazwany, który zostanie powiązany z chronionym zakresem.

Powrót

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcucha.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

setRange(range)

Dostosowuje zakres chroniony. Jeśli podany zakres dotyczy innego obszaru niż bieżący zakres chroniony, ta metoda spowoduje przeniesienie zabezpieczenia do nowego zakresu.

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

Parametry

NazwaTypOpis
rangeRangeNowy zakres chroniący przed zmianami.

Powrót

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcucha.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

setRangeName(rangeName)

Powiąże zakres chroniony z istniejącym zakresem nazwanym. Jeśli zakres nazwany obejmuje inny obszar niż bieżący zakres chroniony, ta metoda powoduje zastąpienie zabezpieczenia w zakresie nazwanym. Zakres nazwany musi się znajdować w tym samym arkuszu co bieżący zakres chroniony. Pamiętaj, że skrypty muszą jawnie wywoływać tę metodę w zakresie nazwanym. Wywołanie Range.protect() w celu utworzenia zabezpieczenia typu Range, które jest zakresem nazwanym, bez wywoływania funkcji setRangeName(rangeName), nie wystarcza. Jednak utworzenie zakresu chronionego na podstawie nazwanego zakresu w interfejsie Arkuszy Google spowoduje automatyczne powiązanie.

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

Parametry

NazwaTypOpis
rangeNameStringNazwa zakresu nazwanego do ochrony.

Powrót

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcucha.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

setUnprotectedRanges(ranges)

Zabezpiecza podaną tablicę zakresów w chronionym arkuszu. Zwraca wyjątek, jeśli obiekt Protection odpowiada zakresowi chronionemu, a nie zabezpieczonemu arkuszowi, lub gdy żaden z zakresów nie znajduje się w chronionym arkuszu. Aby zmienić zakresy niechronione, ustaw nowy zakres zakresów. Aby ponownie zabezpieczyć cały arkusz, ustaw pustą tablicę.

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

Parametry

NazwaTypOpis
rangesRange[]Tablica zakresów, które mają pozostać chronione w chronionym arkuszu.

Powrót

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcucha.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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

setWarningOnly(warningOnly)

Określa, czy ten chroniony zakres korzysta z zabezpieczenia „ostrzegającego”. Ochrona oparta na ostrzeżeniach oznacza, że każdy użytkownik może edytować dane w danym obszarze z wyjątkiem edytowania. Wyświetla jednak ostrzeżenie z prośbą o potwierdzenie zmiany. Domyślnie chronione zakresy i arkusze nie są zależne od ostrzeżeń. Aby sprawdzić stan ostrzeżenia, użyj funkcji 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());

Parametry

NazwaTypOpis
warningOnlyBoolean

Powrót

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcucha.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji za pomocą co najmniej jednego z tych zakresów:

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