Accedere e modificare intervalli e fogli protetti. Un intervallo protetto può proteggere un intervallo statico
di celle o un intervallo denominato. Un foglio protetto può includere regioni non protette. Per i fogli di lavoro creati con la versione precedente di Fogli Google, utilizza la classe .
Page
// Protect range A1:B10, then remove all other users from the list of editors. const ss = SpreadsheetApp.getActive(); const range = ss.getRange('A1:B10'); const protection = range.protect().setDescription('Sample protected range'); // Ensure the current user is an editor before removing others. Otherwise, if // the user's edit permission comes from a group, the script throws an exception // upon removing the group. const me = Session.getEffectiveUser(); protection.addEditor(me); protection.removeEditors(protection.getEditors()); if (protection.canDomainEdit()) { protection.setDomainEdit(false); }
// Remove all range protections in the spreadsheet that the user has permission // to edit. const ss = SpreadsheetApp.getActive(); const protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE); for (let i = 0; i < protections.length; i++) { const protection = protections[i]; if (protection.canEdit()) { protection.remove(); } }
// Protect the active sheet, then remove all other users from the list of // editors. const sheet = SpreadsheetApp.getActiveSheet(); const protection = sheet.protect().setDescription('Sample protected sheet'); // Ensure the current user is an editor before removing others. Otherwise, if // the user's edit permission comes from a group, the script throws an exception // upon removing the group. const me = Session.getEffectiveUser(); protection.addEditor(me); protection.removeEditors(protection.getEditors()); if (protection.canDomainEdit()) { protection.setDomainEdit(false); }
Metodi
| Metodo | Tipo restituito | Breve descrizione |
|---|---|---|
add | Protection | Aggiunge l'utente specificato all'elenco degli editor del foglio o dell'intervallo protetto. |
add | Protection | Aggiunge l'utente specificato all'elenco degli editor del foglio o dell'intervallo protetto. |
add | Protection | Aggiunge l'array di utenti specificato all'elenco degli editor del foglio o dell'intervallo protetto. |
add | Protection | Aggiunge il pubblico di destinazione specificato come editor dell'intervallo protetto. |
can | Boolean | Determina se tutti gli utenti del dominio proprietario del foglio di lavoro hanno l'autorizzazione per modificare l'intervallo o il foglio protetto. |
can | Boolean | Determina se l'utente dispone dell'autorizzazione per modificare l'intervallo o il foglio protetto. |
get | String | Recupera la descrizione dell'intervallo o del foglio protetto. |
get | User[] | Recupera l'elenco degli editor per l'intervallo o il foglio protetto. |
get | Protection | Restituisce il tipo di area protetta, RANGE o SHEET. |
get | Range | Restituisce l'intervallo protetto. |
get | String|null | Restituisce il nome dell'intervallo protetto se è associato a un intervallo denominato. |
get | Target | Restituisce gli ID dei segmenti di pubblico di destinazione che possono modificare l'intervallo protetto. |
get | Range[] | Restituisce un array di intervalli non protetti all'interno di un foglio protetto. |
is | Boolean | Determina se l'area protetta utilizza la protezione "basata sugli avvisi". |
remove() | void | Rimuove la protezione dell'intervallo o del foglio. |
remove | Protection | Rimuove l'utente specificato dall'elenco degli editor del foglio o dell'intervallo protetto. |
remove | Protection | Rimuove l'utente specificato dall'elenco degli editor del foglio o dell'intervallo protetto. |
remove | Protection | Rimuove l'array specificato di utenti dall'elenco degli editor del foglio o dell'intervallo protetto. |
remove | Protection | Rimuove il pubblico di destinazione specificato come editor dell'intervallo protetto. |
set | Protection | Imposta la descrizione dell'intervallo o del foglio protetto. |
set | Protection | Imposta se tutti gli utenti del dominio proprietario del foglio di lavoro hanno l'autorizzazione per modificare l'intervallo o il foglio protetto. |
set | Protection | Associa l'intervallo protetto a un intervallo denominato esistente. |
set | Protection | Regola l'intervallo protetto. |
set | Protection | Associa l'intervallo protetto a un intervallo denominato esistente. |
set | Protection | Rimuove la protezione dall'array specificato di intervalli all'interno di un foglio protetto. |
set | Protection | Specifica se questo intervallo protetto utilizza la protezione "basata su avvisi". |
Documentazione dettagliata
add Editor(emailAddress)
Aggiunge l'utente specificato all'elenco degli editor del foglio o dell'intervallo protetto. Questo metodo non
concede automaticamente all'utente l'autorizzazione a modificare il foglio di lavoro stesso; per farlo
inoltre, chiama 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()); }
Parametri
| Nome | Tipo | Descrizione |
|---|---|---|
email | String | L'indirizzo email dell'utente da aggiungere. |
Indietro
Protection: l'oggetto che rappresenta le impostazioni di protezione, per il concatenamento.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
add Editor(user)
Aggiunge l'utente specificato all'elenco degli editor del foglio o dell'intervallo protetto. Questo metodo non
concede automaticamente all'utente l'autorizzazione a modificare il foglio di lavoro stesso; per farlo
inoltre, chiama 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()); }
Parametri
| Nome | Tipo | Descrizione |
|---|---|---|
user | User | Una rappresentazione dell'utente da aggiungere. |
Indietro
Protection: l'oggetto che rappresenta le impostazioni di protezione, per il concatenamento.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
add Editors(emailAddresses)
Aggiunge l'array di utenti specificato all'elenco degli editor del foglio o dell'intervallo protetto. Questo
metodo non concede automaticamente agli utenti l'autorizzazione a modificare il foglio di lavoro stesso; per farlo
inoltre, chiama 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()); }
Parametri
| Nome | Tipo | Descrizione |
|---|---|---|
email | String[] | Un array di indirizzi email degli utenti da aggiungere. |
Indietro
Protection: l'oggetto che rappresenta le impostazioni di protezione, per il concatenamento.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
add Target Audience(audienceId)
Aggiunge il pubblico di destinazione specificato come editor dell'intervallo protetto.
Parametri
| Nome | Tipo | Descrizione |
|---|---|---|
audience | String | L'ID del pubblico di destinazione da aggiungere. |
Indietro
Protection: l'oggetto che rappresenta le impostazioni di protezione, per il concatenamento.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
can Domain Edit()
Determina se tutti gli utenti del dominio proprietario del foglio di lavoro hanno l'autorizzazione per modificare l'intervallo o il foglio protetto. Genera un'eccezione se l'utente non dispone dell'autorizzazione per modificare l'intervallo o il foglio protetto.
// 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());
Indietro
Boolean — true se tutti gli utenti del dominio proprietario del foglio di lavoro dispongono dell'autorizzazione per
modificare l'intervallo o il foglio protetto; false se non la dispongono.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
can Edit()
Determina se l'utente dispone dell'autorizzazione per modificare l'intervallo o il foglio protetto. Il proprietario del foglio di lavoro può sempre modificare i fogli e gli intervalli protetti.
// Remove all range protections in the spreadsheet that the user has permission // to edit. const ss = SpreadsheetApp.getActive(); const protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE); for (let i = 0; i < protections.length; i++) { const protection = protections[i]; if (protection.canEdit()) { protection.remove(); } }
Indietro
Boolean - true se l'utente dispone dell'autorizzazione per modificare l'intervallo o il foglio protetto; false in caso contrario
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Description()
Recupera la descrizione dell'intervallo o del foglio protetto. Se non è impostata alcuna descrizione, questo metodo restituisce una stringa vuota.
// 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);
Indietro
String: la descrizione dell'intervallo o del foglio protetto oppure una stringa vuota se non è impostata alcuna descrizione.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Editors()
Recupera l'elenco degli editor per l'intervallo o il foglio protetto. Genera un'eccezione se l'utente non dispone dell'autorizzazione per modificare l'intervallo o il foglio protetto.
// Protect the active sheet, then remove all other users from the list of // editors. const sheet = SpreadsheetApp.getActiveSheet(); const protection = sheet.protect().setDescription('Sample protected sheet'); // Ensure the current user is an editor before removing others. Otherwise, if // the user's edit permission comes from a group, the script throws an exception // upon removing the group. const me = Session.getEffectiveUser(); protection.addEditor(me); protection.removeEditors(protection.getEditors()); if (protection.canDomainEdit()) { protection.setDomainEdit(false); }
Indietro
User[]: un array di utenti con l'autorizzazione per modificare l'intervallo o il foglio protetto
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Protection Type()
Restituisce il tipo di area protetta, RANGE o 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());
Indietro
Protection: il tipo di area protetta, RANGE o SHEET.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Range()
Restituisce l'intervallo protetto. Se la protezione si applica al foglio anziché a un intervallo, questo metodo restituisce un intervallo che copre l'intero foglio.
// 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());
Indietro
Range: l'intervallo protetto.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Range Name()
Restituisce il nome dell'intervallo protetto se è associato a un intervallo denominato. Restituisce null se la protezione non è associata a un intervallo denominato. Tieni presente che gli script devono chiamare
esplicitamente set per associare un intervallo protetto a un intervallo denominato; chiamare
Range.protect() per creare una protezione da un Range che è un
intervallo denominato, senza chiamare set, non è sufficiente per associarli. Tuttavia, la creazione di un intervallo protetto da un intervallo denominato nell'interfaccia utente di Fogli Google li associa
automaticamente.
// Protect a named range in a spreadsheet and log the name of the protected // range. const ss = SpreadsheetApp.getActive(); const range = ss.getRange('A1:B10'); const protection = range.protect(); ss.setNamedRange('Test', range); // Create a named range. protection.setRangeName( 'Test'); // Associate the protection with the named range. Logger.log( protection.getRangeName()); // Verify the name of the protected range.
Indietro
String|null: il nome dell'intervallo denominato protetto o null se l'intervallo protetto non è
associato a un intervallo denominato
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Target Audiences()
Restituisce gli ID dei segmenti di pubblico di destinazione che possono modificare l'intervallo protetto.
Indietro
Target: un array degli ID dei segmenti di pubblico di destinazione.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Unprotected Ranges()
Restituisce un array di intervalli non protetti all'interno di un foglio protetto. Se l'oggetto Protection
corrisponde a un intervallo protetto anziché a un foglio protetto, questo metodo restituisce un array vuoto. Per modificare gli intervalli non protetti, utilizza set per impostare un
nuovo array di intervalli; per proteggere nuovamente l'intero foglio, imposta un array vuoto.
// Unprotect cells E2:F5 in addition to any other unprotected ranges in the // protected sheet. const sheet = SpreadsheetApp.getActiveSheet(); const protection = sheet.protect(); const unprotected = protection.getUnprotectedRanges(); unprotected.push(sheet.getRange('E2:F5')); protection.setUnprotectedRanges(unprotected);
Indietro
Range[]: un array di intervalli non protetti all'interno di un foglio protetto
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
is Warning Only()
Determina se l'area protetta utilizza la protezione "basata sugli avvisi". La protezione basata sugli avvisi
significa che ogni utente può modificare i dati nell'area, ma la modifica richiede un avviso che chiede
all'utente di confermare la modifica. Per impostazione predefinita, gli intervalli o i fogli protetti non sono basati su avvisi. Per
passare allo stato di avviso, utilizza set.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Protects the sheet. const sampleProtectedSheet = sheet.protect(); // Sets the warning status for the protected sheet as true. sampleProtectedSheet.setWarningOnly(true); const protectedSheetWarningStatus = sampleProtectedSheet.isWarningOnly(); // Logs the warning status of the protected sheet to the console. console.log(protectedSheetWarningStatus);
Indietro
Boolean — true se l'intervallo o il foglio protetto utilizza solo la protezione basata sugli avvisi.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
remove()
Rimuove la protezione dell'intervallo o del foglio.
// Remove all range protections in the spreadsheet that the user has permission // to edit. const ss = SpreadsheetApp.getActive(); const protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE); for (let i = 0; i < protections.length; i++) { const protection = protections[i]; if (protection.canEdit()) { protection.remove(); } }
// Remove sheet protection from the active sheet, if the user has permission to // edit it. const sheet = SpreadsheetApp.getActiveSheet(); const protection = sheet.getProtections(SpreadsheetApp.ProtectionType.SHEET)[0]; if (protection?.canEdit()) { protection.remove(); }
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
remove Editor(emailAddress)
Rimuove l'utente specificato dall'elenco degli editor del foglio o dell'intervallo protetto. Tieni presente che se l'utente è membro di un gruppo Google con autorizzazione di modifica o se tutti gli utenti del dominio hanno l'autorizzazione di modifica, l'utente potrà comunque modificare l'area protetta. Non è possibile rimuovere né il proprietario del foglio di lavoro né l'utente attuale.
// 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()); }
Parametri
| Nome | Tipo | Descrizione |
|---|---|---|
email | String | L'indirizzo email dell'utente da rimuovere. |
Indietro
Protection: l'oggetto che rappresenta le impostazioni di protezione, per il concatenamento.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
remove Editor(user)
Rimuove l'utente specificato dall'elenco degli editor del foglio o dell'intervallo protetto. Tieni presente che se l'utente è membro di un gruppo Google con autorizzazione di modifica o se tutti gli utenti del dominio hanno l'autorizzazione di modifica, l'utente potrà comunque modificare anche l'area protetta. Non è possibile rimuovere né il proprietario del foglio di lavoro né l'utente corrente.
// 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()); }
Parametri
| Nome | Tipo | Descrizione |
|---|---|---|
user | User | Una rappresentazione dell'utente da rimuovere. |
Indietro
Protection: l'oggetto che rappresenta le impostazioni di protezione, per il concatenamento
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
remove Editors(emailAddresses)
Rimuove l'array specificato di utenti dall'elenco degli editor del foglio o dell'intervallo protetto. Tieni presente che se uno degli utenti è membro di un gruppo Google con autorizzazione di modifica o se tutti gli utenti del dominio hanno l'autorizzazione di modifica, questi utenti potranno comunque modificare l'area protetta. Non è possibile rimuovere il proprietario del foglio di lavoro né l'utente attuale.
// Protect the active sheet, then remove all other users from the list of // editors. const sheet = SpreadsheetApp.getActiveSheet(); const protection = sheet.protect().setDescription('Sample protected sheet'); // Ensure the current user is an editor before removing others. Otherwise, if // the user's edit permission comes from a group, the script throws an exception // upon removing the group. const me = Session.getEffectiveUser(); protection.addEditor(me); protection.removeEditors(protection.getEditors()); if (protection.canDomainEdit()) { protection.setDomainEdit(false); }
Parametri
| Nome | Tipo | Descrizione |
|---|---|---|
email | String[] | Un array di indirizzi email degli utenti da rimuovere. |
Indietro
Protection: l'oggetto che rappresenta le impostazioni di protezione, per il concatenamento
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
remove Target Audience(audienceId)
Rimuove il pubblico di destinazione specificato come editor dell'intervallo protetto.
Parametri
| Nome | Tipo | Descrizione |
|---|---|---|
audience | String | L'ID del pubblico di destinazione da rimuovere. |
Indietro
Protection: l'oggetto che rappresenta le impostazioni di protezione, per il concatenamento.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Description(description)
Imposta la descrizione dell'intervallo o del foglio protetto.
// 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);
Parametri
| Nome | Tipo | Descrizione |
|---|---|---|
description | String | La descrizione dell'intervallo o del foglio protetto. |
Indietro
Protection: l'oggetto che rappresenta le impostazioni di protezione, per il concatenamento.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Domain Edit(editable)
Imposta se tutti gli utenti del dominio proprietario del foglio di lavoro hanno l'autorizzazione per modificare l'intervallo o il foglio protetto. Tieni presente che tutti gli utenti che dispongono dell'autorizzazione di modifica esplicita possono modificare l'area protetta indipendentemente da questa impostazione. Genera un'eccezione se il foglio di lavoro non appartiene a un dominio Google Workspace (ovvero se è di proprietà di un account gmail.com).
Parametri
| Nome | Tipo | Descrizione |
|---|---|---|
editable | Boolean | true se tutti gli utenti del dominio proprietario del foglio di lavoro devono disporre
dell'autorizzazione per modificare l'intervallo o il foglio protetto; false in caso contrario. |
Indietro
Protection: l'oggetto che rappresenta le impostazioni di protezione, per il concatenamento
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Named Range(namedRange)
Associa l'intervallo protetto a un intervallo denominato esistente. Se l'intervallo denominato copre un'area diversa dall'intervallo protetto corrente, questo metodo sposta la protezione in modo che copra l'intervallo denominato. L'intervallo denominato deve trovarsi nello stesso foglio dell'intervallo protetto
corrente. Tieni presente che gli script devono chiamare esplicitamente questo metodo per associare un intervallo protetto a un intervallo denominato; chiamare Range.protect() per creare una protezione da un Range che è un intervallo denominato, senza chiamare set, non è sufficiente per associarli. Tuttavia, la creazione di un intervallo protetto da un intervallo denominato nell'interfaccia utente di Fogli Google li associa automaticamente.
// 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());
Parametri
| Nome | Tipo | Descrizione |
|---|---|---|
named | Named | L'intervallo denominato esistente da associare all'intervallo protetto. |
Indietro
Protection: l'oggetto che rappresenta le impostazioni di protezione, per il concatenamento.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Range(range)
Regola l'intervallo protetto. Se l'intervallo specificato copre un'area diversa da quella attualmente protetta, questo metodo sposta la protezione per coprire il nuovo intervallo.
// 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());
Parametri
| Nome | Tipo | Descrizione |
|---|---|---|
range | Range | Il nuovo intervallo da proteggere dalle modifiche. |
Indietro
Protection: l'oggetto che rappresenta le impostazioni di protezione, per il concatenamento.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Range Name(rangeName)
Associa l'intervallo protetto a un intervallo denominato esistente. Se l'intervallo denominato copre un'area diversa dall'intervallo protetto corrente, questo metodo sposta la protezione in modo che copra l'intervallo denominato. L'intervallo denominato deve trovarsi nello stesso foglio dell'intervallo protetto
corrente. Tieni presente che gli script devono chiamare esplicitamente questo metodo per associare un intervallo protetto a un intervallo denominato; chiamare Range.protect() per creare una protezione da un Range che è un intervallo denominato, senza chiamare set, non è sufficiente per associarli. Tuttavia, la creazione di un intervallo protetto da un intervallo denominato nell'interfaccia utente di Fogli Google li associa automaticamente.
// Protect a named range in a spreadsheet and log the name of the protected // range. const ss = SpreadsheetApp.getActive(); const range = ss.getRange('A1:B10'); const protection = range.protect(); ss.setNamedRange('Test', range); // Create a named range. protection.setRangeName( 'Test'); // Associate the protection with the named range. Logger.log( protection.getRangeName()); // Verify the name of the protected range.
Parametri
| Nome | Tipo | Descrizione |
|---|---|---|
range | String | Il nome dell'intervallo denominato da proteggere. |
Indietro
Protection: l'oggetto che rappresenta le impostazioni di protezione, per il concatenamento
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Unprotected Ranges(ranges)
Rimuove la protezione dall'array specificato di intervalli all'interno di un foglio protetto. Genera un'eccezione se l'oggetto
Protection corrisponde a un intervallo protetto anziché a un foglio protetto o se
uno degli intervalli non si trova nel foglio protetto. Per modificare gli intervalli non protetti, imposta un nuovo
array di intervalli; per proteggere nuovamente l'intero foglio, imposta un array vuoto.
// Protect the active sheet except B2:C5, then remove all other users from the // list of editors. const sheet = SpreadsheetApp.getActiveSheet(); const protection = sheet.protect().setDescription('Sample protected sheet'); const unprotected = sheet.getRange('B2:C5'); protection.setUnprotectedRanges([unprotected]); // Ensure the current user is an editor before removing others. Otherwise, if // the user's edit permission comes from a group, the script throws an exception // upon removing the group. const me = Session.getEffectiveUser(); protection.addEditor(me); protection.removeEditors(protection.getEditors()); if (protection.canDomainEdit()) { protection.setDomainEdit(false); }
Parametri
| Nome | Tipo | Descrizione |
|---|---|---|
ranges | Range[] | L'array di intervalli da lasciare non protetti all'interno di un foglio protetto. |
Indietro
Protection: l'oggetto che rappresenta le impostazioni di protezione, per il concatenamento
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Warning Only(warningOnly)
Specifica se questo intervallo protetto utilizza la protezione "basata su avvisi". La protezione
basata sugli avvisi significa che ogni utente può modificare i dati nell'area, ma la modifica genera un avviso
che chiede all'utente di confermare la modifica. Per impostazione predefinita, gli intervalli o i fogli protetti non
si basano su avvisi. Per controllare lo stato di avviso, utilizza is.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets the sheet 'Sheet1' by its name. const sheet = ss.getSheetByName('Sheet1'); // Protects the sheet and sets the protection to warning-based. const sampleProtectedSheet = sheet.protect().setWarningOnly(true); // Logs whether the protected sheet is warning-based to the console. console.log(sampleProtectedSheet.isWarningOnly());
Parametri
| Nome | Tipo | Descrizione |
|---|---|---|
warning | Boolean |
Indietro
Protection: l'oggetto che rappresenta le impostazioni di protezione, per il concatenamento.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets