सुरक्षित की गई रेंज और शीट को ऐक्सेस और उनमें बदलाव करना. सुरक्षित की गई रेंज, सेल की स्टैटिक रेंज या नाम वाली रेंज को सुरक्षित कर सकती है. सुरक्षित की गई शीट में, असुरक्षित सेल भी हो सकती हैं. Google Sheets के पुराने वर्शन से बनाई गई स्प्रेडशीट के लिए,
क्लास का इस्तेमाल करें.
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); }
तरीके
तरीका | रिटर्न टाइप | संक्षिप्त विवरण |
---|---|---|
add | Protection | यह उपयोगकर्ता को, सुरक्षित की गई शीट या रेंज में बदलाव करने वाले लोगों की सूची में जोड़ता है. |
add | Protection | यह उपयोगकर्ता को, सुरक्षित की गई शीट या रेंज में बदलाव करने वाले लोगों की सूची में जोड़ता है. |
add | Protection | सुरक्षित की गई शीट या रेंज के लिए, एडिटर की सूची में उपयोगकर्ताओं के दिए गए कलेक्शन को जोड़ता है. |
add | Protection | चुनी गई टारगेट ऑडियंस को, सुरक्षित की गई रेंज के एडिटर के तौर पर जोड़ता है. |
can | Boolean | इससे यह तय होता है कि स्प्रेडशीट के मालिकाना हक वाले डोमेन के सभी उपयोगकर्ताओं के पास, सुरक्षित की गई रेंज या शीट में बदलाव करने की अनुमति है या नहीं. |
can | Boolean | इससे यह तय होता है कि उपयोगकर्ता के पास, सुरक्षित की गई रेंज या शीट में बदलाव करने की अनुमति है या नहीं. |
get | String | सुरक्षित की गई रेंज या शीट की जानकारी दिखाता है. |
get | User[] | सुरक्षित की गई रेंज या शीट के लिए, संपादकों की सूची दिखाता है. |
get | Protection | इससे संरक्षित इलाके का टाइप पता चलता है. यह RANGE या SHEET हो सकता है. |
get | Range | वह रेंज दिखाता है जिसे सुरक्षित किया जा रहा है. |
get | String | अगर सुरक्षित की गई रेंज, नाम वाली रेंज से जुड़ी है, तो उसका नाम दिखाता है. |
get | Target | टारगेट ऑडियंस के उन आईडी को दिखाता है जो सुरक्षित रेंज में बदलाव कर सकते हैं. |
get | Range[] | सुरक्षित की गई शीट में, असुरक्षित रेंज का कलेक्शन दिखाता है. |
is | Boolean | इससे यह तय होता है कि सुरक्षित इलाके में "चेतावनी पर आधारित" सुरक्षा का इस्तेमाल किया जा रहा है या नहीं. |
remove() | void | रेंज या शीट को अनलॉक करता है. |
remove | Protection | यह सुविधा, सुरक्षित की गई शीट या रेंज के एडिटर की सूची से किसी उपयोगकर्ता को हटाती है. |
remove | Protection | यह सुविधा, सुरक्षित की गई शीट या रेंज के एडिटर की सूची से किसी उपयोगकर्ता को हटाती है. |
remove | Protection | सुरक्षित की गई शीट या रेंज के लिए, एडिटर की सूची से उपयोगकर्ताओं के दिए गए कलेक्शन को हटाता है. |
remove | Protection | सुरक्षित की गई रेंज के एडिटर के तौर पर, चुनी गई टारगेट ऑडियंस को हटाता है. |
set | Protection | सुरक्षित की गई रेंज या शीट की जानकारी सेट करता है. |
set | Protection | इससे यह तय होता है कि स्प्रेडशीट के मालिकाना हक वाले डोमेन के सभी उपयोगकर्ताओं के पास, सुरक्षित रेंज या शीट में बदलाव करने की अनुमति है या नहीं. |
set | Protection | सुरक्षित की गई रेंज को, नाम वाली किसी मौजूदा रेंज से जोड़ता है. |
set | Protection | सुरक्षित की जा रही रेंज में बदलाव करता है. |
set | Protection | सुरक्षित की गई रेंज को, नाम वाली किसी मौजूदा रेंज से जोड़ता है. |
set | Protection | सुरक्षित की गई शीट में, रेंज के दिए गए कलेक्शन को अनलॉक करता है. |
set | Protection | यह सेट करता है कि सुरक्षित की गई इस रेंज में, "चेतावनी के आधार पर" सुरक्षा का इस्तेमाल किया जा रहा है या नहीं. |
ज़्यादा जानकारी वाला दस्तावेज़
addEditor(emailAddress)
यह उपयोगकर्ता को, सुरक्षित की गई शीट या रेंज में बदलाव करने वाले लोगों की सूची में जोड़ता है. इस तरीके से, उपयोगकर्ता को स्प्रेडशीट में बदलाव करने की अनुमति अपने-आप नहीं मिलती. इसके लिए, Spreadsheet.addEditor(emailAddress)
को कॉल करें.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Adds an editor to the spreadsheet using an email address. // TODO(developer): Replace the email address with a valid email. ss.addEditor('cloudysanfrancisco@gmail.com'); // Gets a sheet by its name and protects it. const sheet = ss.getSheetByName('Sheet1'); const sampleProtectedSheet = sheet.protect(); // Adds an editor of the protected sheet using an email address. // TODO(developer): Replace the email address with a valid email. sampleProtectedSheet.addEditor('cloudysanfrancisco@gmail.com'); // Gets the editors of the protected sheet. const editors = sampleProtectedSheet.getEditors(); // Logs the editors' email addresses to the console. for (const editor of editors) { console.log(editor.getEmail()); }
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
email | String | जो उपयोगकर्ता जोड़ना है उसका ईमेल पता. |
वापसी का टिकट
Protection
— चेन करने के लिए, सुरक्षा सेटिंग दिखाने वाला ऑब्जेक्ट.
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addEditor(user)
यह उपयोगकर्ता को, सुरक्षित की गई शीट या रेंज में बदलाव करने वाले लोगों की सूची में जोड़ता है. इस तरीके से, उपयोगकर्ता को स्प्रेडशीट में बदलाव करने की अनुमति अपने-आप नहीं मिलती. इसके लिए, Spreadsheet.addEditor(user)
को कॉल करें.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Protects the sheet. const sampleProtectedSheet = sheet.protect(); // Adds the active user as an editor of the protected sheet. sampleProtectedSheet.addEditor(Session.getActiveUser()); // Gets the editors of the protected sheet. const editors = sampleProtectedSheet.getEditors(); // Logs the editors' email addresses to the console. for (const editor of editors) { console.log(editor.getEmail()); }
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
user | User | जोड़े जाने वाले उपयोगकर्ता की जानकारी. |
वापसी का टिकट
Protection
— चेन करने के लिए, सुरक्षा सेटिंग दिखाने वाला ऑब्जेक्ट.
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addEditors(emailAddresses)
सुरक्षित की गई शीट या रेंज के लिए, एडिटर की सूची में उपयोगकर्ताओं के दिए गए कलेक्शन को जोड़ता है. इस तरीके से, उपयोगकर्ताओं को स्प्रेडशीट में अपने-आप बदलाव करने की अनुमति नहीं मिलती. इसके लिए, Spreadsheet.addEditors(emailAddresses)
को कॉल करें.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Creates variables for the email addresses to add as editors. // TODO(developer): Replace the email addresses with valid ones. const TEST_EMAIL_1 = 'cloudysanfrancisco@gmail.com'; const TEST_EMAIL_2 = 'baklavainthebalkans@gmail.com'; // Protects the sheet. const sampleProtectedSheet = sheet.protect(); // Adds editors to the protected sheet using the email address variables. sampleProtectedSheet.addEditors([TEST_EMAIL_1, TEST_EMAIL_2]); // Gets the editors of the protected sheet. const editors = sampleProtectedSheet.getEditors(); // Logs the editors' email addresses to the console. for (const editor of editors) { console.log(editor.getEmail()); }
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
email | String[] | जोड़े जाने वाले उपयोगकर्ताओं के ईमेल पतों का कलेक्शन. |
वापसी का टिकट
Protection
— चेन करने के लिए, सुरक्षा सेटिंग दिखाने वाला ऑब्जेक्ट.
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addTargetAudience(audienceId)
चुनी गई टारगेट ऑडियंस को, सुरक्षित की गई रेंज के एडिटर के तौर पर जोड़ता है.
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
audience | String | जोड़ने के लिए टारगेट ऑडियंस का आईडी. |
वापसी का टिकट
Protection
— चेन करने के लिए, सुरक्षा सेटिंग दिखाने वाला ऑब्जेक्ट.
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
canDomainEdit()
इससे यह तय होता है कि स्प्रेडशीट के मालिकाना हक वाले डोमेन के सभी उपयोगकर्ताओं के पास, सुरक्षित की गई रेंज या शीट में बदलाव करने की अनुमति है या नहीं. अगर उपयोगकर्ता के पास सुरक्षित रेंज या शीट में बदलाव करने की अनुमति नहीं है, तो यह एक अपवाद दिखाता है.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Protects the sheet. const sampleProtectedSheet = sheet.protect(); // Logs whether domain users have permission to edit the protected sheet to the // console. console.log(sampleProtectedSheet.canDomainEdit());
वापसी का टिकट
Boolean
— true
अगर स्प्रेडशीट का मालिकाना हक रखने वाले डोमेन के सभी उपयोगकर्ताओं के पास, सुरक्षित रेंज या शीट में बदलाव करने की अनुमति है, तो true
. अगर उनके पास यह अनुमति नहीं है, तो Boolean
.false
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
canEdit()
इससे यह तय होता है कि उपयोगकर्ता के पास, सुरक्षित की गई रेंज या शीट में बदलाव करने की अनुमति है या नहीं. स्प्रेडशीट का मालिक, सुरक्षित रेंज और शीट में कभी भी बदलाव कर सकता है.
// Remove all range protections in the spreadsheet that the user has permission // to edit. 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(); } }
वापसी का टिकट
Boolean
— true
अगर उपयोगकर्ता के पास सुरक्षित रेंज या शीट में बदलाव करने की अनुमति है, तो false
नहीं है
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDescription()
सुरक्षित की गई रेंज या शीट की जानकारी दिखाता है. अगर कोई ब्यौरा सेट नहीं किया गया है, तो यह तरीका एक खाली स्ट्रिंग दिखाता है.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Protects the sheet and sets the description. const sampleProtectedSheet = sheet.protect().setDescription('Sample sheet is protected'); // Gets the description of the protected sheet and logs it to the console. const sampleProtectedSheetDescription = sampleProtectedSheet.getDescription(); console.log(sampleProtectedSheetDescription);
वापसी का टिकट
String
— सुरक्षित की गई रेंज या शीट की जानकारी. अगर कोई जानकारी सेट नहीं की गई है, तो खाली स्ट्रिंग.
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getEditors()
सुरक्षित की गई रेंज या शीट के लिए, संपादकों की सूची दिखाता है. अगर उपयोगकर्ता के पास सुरक्षित रेंज या शीट में बदलाव करने की अनुमति नहीं है, तो यह एक अपवाद दिखाता है.
// Protect the active sheet, then remove all other users from the list of // editors. 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); }
वापसी का टिकट
User[]
— सुरक्षित की गई रेंज या शीट में बदलाव करने की अनुमति वाले उपयोगकर्ताओं का कलेक्शन
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getProtectionType()
इससे संरक्षित इलाके का टाइप पता चलता है. यह RANGE
या SHEET
हो सकता है.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Protects the sheet. const sampleProtectedSheet = sheet.protect(); // Gets the type of the protected area. const protectionType = sampleProtectedSheet.getProtectionType(); // Logs 'SHEET'to the console since the type of the protected area is a sheet. console.log(protectionType.toString());
वापसी का टिकट
Protection
— संरक्षित इलाके का टाइप, RANGE
या SHEET
.
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getRange()
वह रेंज दिखाता है जिसे सुरक्षित किया जा रहा है. अगर सुरक्षा किसी रेंज के बजाय शीट पर लागू होती है, तो यह तरीका पूरी शीट की रेंज दिखाता है.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets the range 'A1:B10' of Sheet1. const range = sheet.getRange('A1:B10'); // Makes cells A1:B10 a protected range. const sampleProtectedRange = range.protect(); // Gets the protected ranges on the sheet. const protections = sheet.getProtections(SpreadsheetApp.ProtectionType.RANGE); // Logs the A1 notation of the first protected range on the sheet. console.log(protections[0].getRange().getA1Notation());
वापसी का टिकट
Range
— वह रेंज जिसे सुरक्षित किया जा रहा है.
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getRangeName()
अगर सुरक्षित की गई रेंज, नाम वाली रेंज से जुड़ी है, तो उसका नाम दिखाता है. अगर सुरक्षा, नाम वाले किसी रेंज से नहीं जुड़ी है, तो null
दिखाता है. ध्यान दें कि स्क्रिप्ट को, सुरक्षित की गई रेंज को नाम वाली रेंज से जोड़ने के लिए, set
को साफ़ तौर पर कॉल करना होगा. Range
से सुरक्षा बनाने के लिए Range.protect()
को कॉल करना, set
को कॉल किए बिना, उन्हें जोड़ने के लिए ज़रूरी नहीं है. हालांकि, Google Sheets के यूज़र इंटरफ़ेस (यूआई) में, नाम वाली रेंज से सुरक्षित रेंज बनाने पर, दोनों को अपने-आप जोड़ दिया जाता है.
// 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.
वापसी का टिकट
String
— सुरक्षित की गई नाम वाली रेंज का नाम या null
, अगर सुरक्षित की गई रेंज किसी नाम वाली रेंज से नहीं जुड़ी है
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getTargetAudiences()
टारगेट ऑडियंस के उन आईडी को दिखाता है जो सुरक्षित रेंज में बदलाव कर सकते हैं.
वापसी का टिकट
Target
— टारगेट ऑडियंस के आईडी का कलेक्शन.
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getUnprotectedRanges()
सुरक्षित की गई शीट में, असुरक्षित रेंज का कलेक्शन दिखाता है. अगर Protection
ऑब्जेक्ट, सुरक्षित की गई शीट के बजाय सुरक्षित की गई रेंज से जुड़ा है, तो यह तरीका खाली कलेक्शन दिखाता है. बिना सुरक्षा वाली रेंज बदलने के लिए, रेंज का नया कलेक्शन सेट करने के लिए set
का इस्तेमाल करें. पूरी शीट को फिर से सुरक्षित करने के लिए, खाली कलेक्शन सेट करें.
// 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);
वापसी का टिकट
Range[]
— सुरक्षित की गई शीट में, सुरक्षित नहीं की गई रेंज का कलेक्शन
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isWarningOnly()
इससे यह तय होता है कि सुरक्षित इलाके में "चेतावनी पर आधारित" सुरक्षा का इस्तेमाल किया जा रहा है या नहीं. चेतावनी के आधार पर सुरक्षा का मतलब है कि हर उपयोगकर्ता उस सेक्शन में डेटा में बदलाव कर सकता है. हालांकि, बदलाव करने पर चेतावनी दिखती है और उपयोगकर्ता से बदलाव की पुष्टि करने के लिए कहा जाता है. डिफ़ॉल्ट रूप से, सुरक्षित की गई रेंज या शीट, चेतावनी पर आधारित नहीं होती हैं. चेतावनी वाली स्थिति में बदलने के लिए, 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);
वापसी का टिकट
Boolean
— true
अगर सुरक्षित की गई रेंज या शीट में, सिर्फ़ चेतावनी के आधार पर सुरक्षा का इस्तेमाल किया जा रहा है.
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
remove()
रेंज या शीट को अनलॉक करता है.
// Remove all range protections in the spreadsheet that the user has permission // to edit. 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(); }
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeEditor(emailAddress)
यह सुविधा, सुरक्षित की गई शीट या रेंज के एडिटर की सूची से किसी उपयोगकर्ता को हटाती है. ध्यान दें कि अगर उपयोगकर्ता, बदलाव करने की अनुमति वाले किसी Google ग्रुप का सदस्य है या डोमेन के सभी उपयोगकर्ताओं के पास बदलाव करने की अनुमति है, तो वह सुरक्षित सेक्शन में बदलाव कर सकता है. स्प्रेडशीट के मालिक या मौजूदा उपयोगकर्ता को नहीं हटाया जा सकता.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Creates a variable for an email address. // TODO(developer): Replace the email address with a valid one. const TEST_EMAIL = 'baklavainthebalkans@gmail.com'; // Protects the sheet. const sampleProtectedSheet = sheet.protect(); // Adds an editor to the protected sheet using the email address variable. sampleProtectedSheet.addEditor(TEST_EMAIL); // Removes the editor from the protected sheet using the email address variable. sampleProtectedSheet.removeEditor(TEST_EMAIL); // Gets the editors of the protected sheet. const editors = sampleProtectedSheet.getEditors(); // Logs the editors' email addresses to the console. for (const editor of editors) { console.log(editor.getEmail()); }
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
email | String | जिस उपयोगकर्ता को हटाना है उसका ईमेल पता. |
वापसी का टिकट
Protection
— चेन करने के लिए, सुरक्षा सेटिंग दिखाने वाला ऑब्जेक्ट.
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeEditor(user)
यह सुविधा, सुरक्षित की गई शीट या रेंज के एडिटर की सूची से किसी उपयोगकर्ता को हटाती है. ध्यान दें कि अगर उपयोगकर्ता, बदलाव करने की अनुमति वाले किसी Google ग्रुप का सदस्य है या डोमेन के सभी उपयोगकर्ताओं के पास बदलाव करने की अनुमति है, तो वह सुरक्षित सेक्शन में भी बदलाव कर सकता है. स्प्रेडशीट के मालिक या मौजूदा उपयोगकर्ता को नहीं हटाया जा सकता.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Protects the sheet. const sampleProtectedSheet = sheet.protect(); // Removes the active user from the editors of the protected sheet. sampleProtectedSheet.removeEditor(Session.getActiveUser()); // Gets the editors of the protected sheet. const editors = sampleProtectedSheet.getEditors(); // Logs the editors' email addresses to the console. for (const editor of editors) { console.log(editor.getEmail()); }
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
user | User | हटाए जाने वाले उपयोगकर्ता की जानकारी. |
वापसी का टिकट
Protection
— चेन करने के लिए, सुरक्षा सेटिंग दिखाने वाला ऑब्जेक्ट
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeEditors(emailAddresses)
सुरक्षित की गई शीट या रेंज के लिए, एडिटर की सूची से उपयोगकर्ताओं के दिए गए कलेक्शन को हटाता है. ध्यान दें कि अगर कोई उपयोगकर्ता, बदलाव करने की अनुमति वाले Google ग्रुप का सदस्य है या डोमेन के सभी उपयोगकर्ताओं के पास बदलाव करने की अनुमति है, तो वे उपयोगकर्ता अब भी सुरक्षित सेक्शन में बदलाव कर पाएंगे. स्प्रेडशीट के मालिक या मौजूदा उपयोगकर्ता को हटाया नहीं जा सकता.
// Protect the active sheet, then remove all other users from the list of // editors. 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); }
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
email | String[] | हटाए जाने वाले उपयोगकर्ताओं के ईमेल पतों का कलेक्शन. |
वापसी का टिकट
Protection
— चेन करने के लिए, सुरक्षा सेटिंग दिखाने वाला ऑब्जेक्ट
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeTargetAudience(audienceId)
सुरक्षित की गई रेंज के एडिटर के तौर पर, चुनी गई टारगेट ऑडियंस को हटाता है.
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
audience | String | हटाने के लिए टारगेट ऑडियंस का आईडी. |
वापसी का टिकट
Protection
— चेन करने के लिए, सुरक्षा सेटिंग दिखाने वाला ऑब्जेक्ट.
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setDescription(description)
सुरक्षित की गई रेंज या शीट की जानकारी सेट करता है.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets the sheet 'Sheet1' by its name. const sheet = ss.getSheetByName('Sheet1'); // Protects the sheet. const sampleProtectedSheet = sheet.protect(); // Sets the sheet description to 'Sheet1 is protected.' sampleProtectedSheet.setDescription('Sheet1 is protected'); // Gets the description of the protected sheet. const sampleProtectedSheetDescription = sampleProtectedSheet.getDescription(); // Logs the description of the protected sheet to the console. console.log(sampleProtectedSheetDescription);
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
description | String | सुरक्षित की गई रेंज या शीट की जानकारी. |
वापसी का टिकट
Protection
— चेन करने के लिए, सुरक्षा सेटिंग दिखाने वाला ऑब्जेक्ट.
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setDomainEdit(editable)
इससे यह तय होता है कि स्प्रेडशीट के मालिकाना हक वाले डोमेन के सभी उपयोगकर्ताओं के पास, सुरक्षित रेंज या शीट में बदलाव करने की अनुमति है या नहीं. ध्यान दें कि जिन उपयोगकर्ताओं के पास बदलाव करने की अनुमति है वे इस सेटिंग के बावजूद, सुरक्षित किए गए हिस्से में बदलाव कर सकते हैं. अगर स्प्रेडशीट, Google Workspace डोमेन से नहीं जुड़ी है, तो यह अपवाद दिखाता है. इसका मतलब है कि अगर स्प्रेडशीट का मालिकाना हक किसी gmail.com खाते के पास है.
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
editable | Boolean | true अगर स्प्रेडशीट का मालिकाना हक रखने वाले डोमेन के सभी उपयोगकर्ताओं के पास, सुरक्षित की गई रेंज या शीट में बदलाव करने की अनुमति होनी चाहिए; false अगर नहीं. |
वापसी का टिकट
Protection
— चेन करने के लिए, सुरक्षा सेटिंग दिखाने वाला ऑब्जेक्ट
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setNamedRange(namedRange)
सुरक्षित की गई रेंज को, नाम वाली किसी मौजूदा रेंज से जोड़ता है. अगर नाम वाली रेंज, मौजूदा सुरक्षित रेंज से अलग एरिया को कवर करती है, तो यह तरीका सुरक्षा को नाम वाली रेंज को कवर करने के लिए ले जाता है. नाम वाली रेंज, सुरक्षित की गई मौजूदा रेंज वाली शीट पर होनी चाहिए. ध्यान दें कि सुरक्षित की गई रेंज को नाम वाली रेंज से जोड़ने के लिए, स्क्रिप्ट को इस मेथड को साफ़ तौर पर कॉल करना होगा. नाम वाली रेंज Range
से सुरक्षा बनाने के लिए, Range.protect()
को कॉल करना और set
को कॉल न करना, दोनों को जोड़ने के लिए ज़रूरी नहीं है. हालांकि, Google Sheets के यूज़र इंटरफ़ेस (यूआई) में, नाम वाली रेंज से सुरक्षित रेंज बनाने पर, दोनों अपने-आप जुड़ जाती हैं.
// 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());
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
named | Named | सुरक्षित की गई रेंज से जोड़ने के लिए, नाम वाली मौजूदा रेंज. |
वापसी का टिकट
Protection
— चेन करने के लिए, सुरक्षा सेटिंग दिखाने वाला ऑब्जेक्ट.
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setRange(range)
सुरक्षित की जा रही रेंज में बदलाव करता है. अगर दी गई रेंज, सुरक्षित की गई मौजूदा रेंज से अलग एरिया को कवर करती है, तो यह तरीका सुरक्षा को नई रेंज पर ले जाता है.
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Protects cells A1:D10 on Sheet1 of the spreadsheet. const sheet = ss.getSheetByName('Sheet1'); const protectedRange = sheet.getRange('A1:D10').protect(); // Logs the original protected range, A1:D10, to the console. console.log(protectedRange.getRange().getA1Notation()); // Gets the range E1:J10. const newRange = sheet.getRange('E1:J10'); // Updates the protected range to E1:J10. protectedRange.setRange(newRange); // Logs the updated protected range to the console. console.log(protectedRange.getRange().getA1Notation());
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
range | Range | बदलावों से सुरक्षित रखने के लिए नई रेंज. |
वापसी का टिकट
Protection
— चेन करने के लिए, सुरक्षा सेटिंग दिखाने वाला ऑब्जेक्ट.
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setRangeName(rangeName)
सुरक्षित की गई रेंज को, नाम वाली किसी मौजूदा रेंज से जोड़ता है. अगर नाम वाली रेंज, मौजूदा सुरक्षित रेंज से अलग एरिया को कवर करती है, तो यह तरीका सुरक्षा को नाम वाली रेंज को कवर करने के लिए ले जाता है. नाम वाली रेंज, सुरक्षित की गई मौजूदा रेंज वाली शीट पर होनी चाहिए. ध्यान दें कि सुरक्षित की गई रेंज को नाम वाली रेंज से जोड़ने के लिए, स्क्रिप्ट को इस मेथड को साफ़ तौर पर कॉल करना होगा. नाम वाली रेंज Range
से सुरक्षा बनाने के लिए, Range.protect()
को कॉल करना और set
को कॉल न करना, दोनों को जोड़ने के लिए ज़रूरी नहीं है. हालांकि, Google Sheets के यूज़र इंटरफ़ेस (यूआई) में, नाम वाली रेंज से सुरक्षित रेंज बनाने पर, दोनों अपने-आप जुड़ जाती हैं.
// 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.
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
range | String | जिस नाम वाली रेंज को सुरक्षित करना है उसका नाम. |
वापसी का टिकट
Protection
— चेन करने के लिए, सुरक्षा सेटिंग दिखाने वाला ऑब्जेक्ट
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setUnprotectedRanges(ranges)
सुरक्षित की गई शीट में, रेंज के दिए गए कलेक्शन को अनलॉक करता है. अगर Protection
ऑब्जेक्ट, सुरक्षित शीट के बजाय सुरक्षित रेंज से जुड़ा है या कोई भी रेंज, सुरक्षित शीट पर नहीं है, तो यह एक अपवाद दिखाता है. असुरक्षित रेंज बदलने के लिए, रेंज का नया ऐरे सेट करें. पूरी शीट को फिर से सुरक्षित करने के लिए, खाली ऐरे सेट करें.
// Protect the active sheet except B2:C5, then remove all other users from the // list of editors. 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); }
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
ranges | Range[] | सुरक्षित की गई शीट में, असुरक्षित छोड़ी जाने वाली रेंज का कलेक्शन. |
वापसी का टिकट
Protection
— चेन करने के लिए, सुरक्षा सेटिंग दिखाने वाला ऑब्जेक्ट
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setWarningOnly(warningOnly)
यह सेट करता है कि सुरक्षित की गई इस रेंज में, "चेतावनी के आधार पर" सुरक्षा का इस्तेमाल किया जा रहा है या नहीं. चेतावनी के आधार पर सुरक्षा का मतलब है कि हर उपयोगकर्ता उस सेक्शन में डेटा में बदलाव कर सकता है. हालांकि, बदलाव करने पर चेतावनी दिखती है और उपयोगकर्ता से बदलाव की पुष्टि करने के लिए कहा जाता है. डिफ़ॉल्ट रूप से, सुरक्षित की गई रेंज या शीट, चेतावनी पर आधारित नहीं होती हैं. चेतावनी की स्थिति देखने के लिए, 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());
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
warning | Boolean |
वापसी का टिकट
Protection
— चेन करने के लिए, सुरक्षा सेटिंग दिखाने वाला ऑब्जेक्ट.
अनुमति देना
इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या एक से ज़्यादा स्कोप के लिए अनुमति की ज़रूरत होती है:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets