Class Protection

Ochrona

Otwieranie i modyfikowanie chronionych zakresów i arkuszy. Chroniony zakres może chronić zarówno zakres statyczny, jak i nazwany. Chroniony arkusz może zawierać niechronione regiony. 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 chronionego arkusza lub zakresu.
addEditor(user)ProtectionDodaje danego użytkownika do listy edytorów chronionego arkusza lub zakresu.
addEditors(emailAddresses)ProtectionDodaje podaną tablicę użytkowników do listy edytorów chronionego arkusza lub zakresu.
addTargetAudience(audienceId)ProtectionDodaje określoną grupę odbiorców jako edytor zakresu chronionego.
canDomainEdit()BooleanOkreśla, czy wszyscy użytkownicy w domenie będącej właścicielem arkusza kalkulacyjnego mają uprawnienia do edytowania chronionego zakresu lub arkusza.
canEdit()BooleanOkreśla, czy użytkownik ma uprawnienia do edytowania zakresu chronionego lub arkusza.
getDescription()StringPobiera opis chronionego zakresu lub arkusza.
getEditors()User[]Pobiera listę edytorów zakresu chronionego lub arkusza.
getProtectionType()ProtectionTypePobiera typ obszaru chronionego – RANGE lub SHEET.
getRange()RangePobiera zakres, który jest chroniony.
getRangeName()StringPobiera nazwę zakresu chronionego, jeśli jest on powiązany z zakresem nazwanym.
getTargetAudiences()TargetAudience[]Zwraca identyfikatory grup odbiorców, którzy mogą edytować zakres chroniony.
getUnprotectedRanges()Range[]Pobiera tablicę zakresów niechronionych w chronionym arkuszu.
isWarningOnly()BooleanOkreśla, czy obszar chroniony jest objęty ochroną „opartą na ostrzeżeniach”.
remove()voidPowoduje anulowanie ochrony zakresu lub arkusza.
removeEditor(emailAddress)ProtectionUsuwa danego użytkownika z listy edytorów chronionego arkusza lub zakresu.
removeEditor(user)ProtectionUsuwa danego użytkownika z listy edytorów chronionego arkusza lub zakresu.
removeEditors(emailAddresses)ProtectionUsuwa podaną tablicę użytkowników z listy edytorów chronionego arkusza lub zakresu.
removeTargetAudience(audienceId)ProtectionUsuwa wskazaną grupę odbiorców z uprawnieniami do edycji zakresu chronionego.
setDescription(description)ProtectionUstawia opis zakresu lub arkusza chronionego.
setDomainEdit(editable)ProtectionOkreśla, czy wszyscy użytkownicy w domenie będącej właścicielem arkusza kalkulacyjnego mają uprawnienia do edytowania chronionego zakresu lub arkusza.
setNamedRange(namedRange)ProtectionWiąże zakres chroniony z istniejącym zakresem nazwanym.
setRange(range)ProtectionPozwala dostosować chroniony zakres.
setRangeName(rangeName)ProtectionWiąże zakres chroniony z istniejącym zakresem nazwanym.
setUnprotectedRanges(ranges)ProtectionWyłącza ochronę podanej tablicy zakresów w chronionym arkuszu.
setWarningOnly(warningOnly)ProtectionOkreśla, czy ten zakres chroniony używa ochrony opartej na ostrzeżeniach.

Szczegółowa dokumentacja

addEditor(emailAddress)

Dodaje danego użytkownika do listy edytorów chronionego arkusza lub zakresu. Ta metoda nie przyznaje automatycznie użytkownikowi uprawnień do edycji samego arkusza kalkulacyjnego. Aby to zrobić, dodatkowo 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ć.

Powroty

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcuchów.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji z co najmniej jednym 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 chronionego arkusza lub zakresu. Ta metoda nie przyznaje automatycznie użytkownikowi uprawnień do edycji samego arkusza kalkulacyjnego. Aby to zrobić, dodatkowo 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, który ma zostać dodany.

Powroty

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcuchów.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji z co najmniej jednym 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 chronionego arkusza lub zakresu. Ta metoda nie daje użytkownikom automatycznie uprawnień do edytowania arkusza kalkulacyjnego. Aby to zrobić, należy też 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.

Powroty

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcuchów.

Upoważnienie

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

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

addTargetAudience(audienceId)

Dodaje określoną grupę odbiorców jako edytor zakresu chronionego.

Parametry

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

Powroty

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcuchów.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji z co najmniej jednym 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 będącej właścicielem arkusza kalkulacyjnego mają uprawnienia do edytowania chronionego zakresu lub arkusza. Zgłasza wyjątek, jeśli użytkownik nie ma uprawnień do edytowania 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 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());

Powroty

Booleantrue, jeśli wszyscy użytkownicy w domenie będącej właścicielem arkusza kalkulacyjnego mają uprawnienia do edytowania chronionego zakresu lub arkusza; jeśli nie mają uprawnień do edycji: false.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji z co najmniej jednym 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 zakresu chronionego 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();
  }
}

Powroty

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

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji z co najmniej jednym 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 opis nie jest ustawiony, metoda zwraca pusty ciąg znaków.

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

Powroty

String – opis chronionego zakresu lub arkusza albo pustego ciągu, jeśli nie ustawiono opisu.

Upoważnienie

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

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

getEditors()

Pobiera listę edytorów zakresu chronionego lub arkusza. Zwraca 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);
}

Powroty

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

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji z co najmniej jednym 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());

Powroty

ProtectionType – typ obszaru chronionego, RANGE lub SHEET.

Upoważnienie

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

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

getRange()

Pobiera zakres, który jest chroniony. Jeśli zabezpieczenie ma zastosowanie do arkusza, a nie do zakresu, 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());

Powroty

Range – zakres, który jest chroniony.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji z co najmniej jednym 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 zakresem nazwanym. Zwraca wartość null, jeśli zabezpieczenie nie jest powiązane z nazwanym zakresem. Pamiętaj, że skrypty muszą wyraźnie wywoływać zakres setRangeName(rangeName), aby powiązać zakres chroniony z nazwanym zakresem. Wywołanie funkcji Range.protect() w celu utworzenia zabezpieczenia z Range, który jest zakresem nazwanym bez wywoływania setRangeName(rangeName), nie wystarczy, aby je powiązać. Utworzenie zakresu chronionego z nazwanego zakresu w interfejsie Arkuszy Google powoduje jednak 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.

Powroty

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

Upoważnienie

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

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

getTargetAudiences()

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

Powroty

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

Upoważnienie

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

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

getUnprotectedRanges()

Pobiera tablicę zakresów niechronionych w chronionym arkuszu. Jeśli obiekt Protection odpowiada zakresowi chronionemu, a nie arkuszowi chronionemu, ta metoda zwraca pustą tablicę. Aby zmienić niechronione zakresy, użyj funkcji setUnprotectedRanges(ranges) do ustawienia nowej tablicy zakresów. Aby ponownie chronić 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);

Powroty

Range[] – tablica niechronionych zakresów w chronionym arkuszu.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji z co najmniej jednym 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ą „opartą na ostrzeżeniach”. Ochrona oparta na ostrzeżeniach oznacza, że każdy użytkownik może edytować dane w tym obszarze, ale nie dotyczy to edycji, która wyświetla ostrzeżenie 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);

Powroty

Booleantrue, jeśli chroniony zakres lub arkusz używają tylko ochrony opartej na ostrzeżeniach.

Upoważnienie

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

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

remove()

Powoduje anulowanie ochrony zakresu lub arkusza.

// 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 z co najmniej jednym z tych zakresów:

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

removeEditor(emailAddress)

Usuwa danego użytkownika z listy edytorów 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, użytkownik nadal może edytować obszar chroniony. Nie można usunąć ani 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ąć.

Powroty

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcuchów.

Upoważnienie

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

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

removeEditor(user)

Usuwa danego użytkownika z listy edytorów 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, użytkownik nadal może też edytować obszar chroniony. Nie można usunąć ani właściciela arkusza kalkulacyjnego, ani obecnego 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, który ma zostać usunięty.

Powroty

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcuchów;

Upoważnienie

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

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

removeEditors(emailAddresses)

Usuwa podaną tablicę użytkowników z listy edytorów chronionego arkusza lub zakresu. Pamiętaj, że jeśli dowolny z użytkowników jest członkiem grupy dyskusyjnej Google, która ma uprawnienia do edycji, lub jeśli wszyscy użytkownicy w domenie mają uprawnienia do edycji, nadal mogą edytować chroniony obszar. 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.

Powroty

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcuchów;

Upoważnienie

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

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

removeTargetAudience(audienceId)

Usuwa wskazaną grupę odbiorców z uprawnieniami do edycji zakresu chronionego.

Parametry

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

Powroty

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcuchów.

Upoważnienie

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

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

setDescription(description)

Ustawia opis 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 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.

Powroty

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcuchów.

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji z co najmniej jednym 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 będącej właścicielem arkusza kalkulacyjnego mają uprawnienia do edytowania chronionego zakresu lub arkusza. Pamiętaj, że wszyscy użytkownicy, którzy mają wyraźne uprawnienia do edycji, mogą edytować obszar chroniony niezależnie od tego ustawienia. Tworzy wyjątek, jeśli arkusz kalkulacyjny nie należy do domeny Google Workspace (czyli jeśli należy on 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; w przeciwnym razie false.

Powroty

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcuchów;

Upoważnienie

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

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

setNamedRange(namedRange)

Wiąże zakres chroniony z istniejącym zakresem nazwanym. Jeśli zakres nazwany obejmuje inny obszar niż bieżący zakres chroniony, ta metoda przenosi zabezpieczenie na cały nazwany zakres. Nazwany zakres musi znajdować się w tym samym arkuszu co bieżący zakres chroniony. Skrypty muszą wyraźnie wywoływać tę metodę w celu powiązania chronionego zakresu z nazwanym zakresem. Wywołanie funkcji Range.protect() w celu utworzenia ochrony z zakresu Range, który jest zakresem nazwanym bez wywoływania funkcji setRangeName(rangeName), nie wystarczy do powiązania zakresu. Utworzenie zakresu chronionego z nazwanego zakresu w interfejsie Arkuszy Google powoduje jednak automatyczne powiązanie tych zakresów.

// 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 do powiązania z zakresem chronionym.

Powroty

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcuchów.

Upoważnienie

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

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

setRange(range)

Pozwala dostosować chroniony zakres. Jeśli podany zakres obejmuje inny obszar niż bieżący zakres chroniony, ta metoda przenosi zabezpieczenie na nowy zakres.

// 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 chroniony przed zmianami.

Powroty

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcuchów.

Upoważnienie

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

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

setRangeName(rangeName)

Wiąże zakres chroniony z istniejącym zakresem nazwanym. Jeśli zakres nazwany obejmuje inny obszar niż bieżący zakres chroniony, ta metoda przenosi zabezpieczenie na cały nazwany zakres. Nazwany zakres musi znajdować się w tym samym arkuszu co bieżący zakres chroniony. Skrypty muszą wyraźnie wywoływać tę metodę w celu powiązania chronionego zakresu z nazwanym zakresem. Wywołanie funkcji Range.protect() w celu utworzenia ochrony z zakresu Range, który jest zakresem nazwanym bez wywoływania funkcji setRangeName(rangeName), nie wystarczy do powiązania zakresu. Utworzenie zakresu chronionego z nazwanego zakresu w interfejsie Arkuszy Google powoduje jednak automatyczne powiązanie tych zakresów.

// 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 nazwanego zakresu, który ma być chroniony.

Powroty

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcuchów;

Upoważnienie

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

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

setUnprotectedRanges(ranges)

Wyłącza ochronę podanej tablicy zakresów w chronionym arkuszu. Zgłasza wyjątek, jeśli obiekt Protection odpowiada zakresowi chronionemu, a nie arkuszowi chronionemu lub jeśli którykolwiek z zakresów nie znajduje się w chronionym arkuszu. Aby zmienić zakresy niechronione, ustaw nową tablicę zakresów. Aby ponownie chronić 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ć niechronione w chronionym arkuszu.

Powroty

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcuchów;

Upoważnienie

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

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

setWarningOnly(warningOnly)

Określa, czy ten zakres chroniony używa ochrony opartej na ostrzeżeniach. Ochrona oparta na ostrzeżeniach oznacza, że każdy użytkownik może edytować dane w tym obszarze. Wyjątkiem są zmiany, które powodują wyświetlenie ostrzeżenia z prośbą o potwierdzenie zmiany. Domyślnie chronione zakresy i arkusze nie są oparte na ostrzeżeniach. Aby sprawdzić stan ostrzeżenia, użyj 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

Powroty

Protection – obiekt reprezentujący ustawienia zabezpieczeń na potrzeby łańcuchów.

Upoważnienie

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

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