Class Protection

सुरक्षा के लिए

सुरक्षित की गई रेंज और शीट को ऐक्सेस और उनमें बदलाव करना. सुरक्षित की गई रेंज, सेल की स्टैटिक रेंज या नाम वाली रेंज को सुरक्षित रख सकती है. सुरक्षित की गई किसी शीट में, असुरक्षित किए गए हिस्से शामिल हो सकते हैं. Google Sheets के पुराने वर्शन से बनाई गई स्प्रैडशीट के लिए, PageProtection क्लास का इस्तेमाल करें.

मौजूदा सुरक्षा सुविधाओं को वापस पाने के लिए, Sheet.getProtections(type) या Spreadsheet.getProtections(type) का इस्तेमाल करें.

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

तरीके

तरीकारिटर्न टाइपसंक्षिप्त विवरण
addEditor(emailAddress)Protectionइस फ़ंक्शन का इस्तेमाल करके, सुरक्षित की गई शीट या रेंज के लिए, दिए गए उपयोगकर्ता को एडिटर की सूची में जोड़ा जाता है.
addEditor(user)Protectionइस फ़ंक्शन का इस्तेमाल करके, सुरक्षित की गई शीट या रेंज के लिए, दिए गए उपयोगकर्ता को एडिटर की सूची में जोड़ा जाता है.
addEditors(emailAddresses)Protectionयह फ़ंक्शन, सुरक्षित की गई शीट या रेंज के लिए, एडिटर की सूची में उपयोगकर्ताओं की दी गई ऐरे को जोड़ता है.
addTargetAudience(audienceId)Protectionयह फ़ंक्शन, सुरक्षित की गई रेंज के एडिटर के तौर पर, चुनी गई टारगेट ऑडियंस को जोड़ता है.
canDomainEdit()Booleanइससे यह तय होता है कि स्प्रेडशीट के मालिक वाले डोमेन के सभी उपयोगकर्ताओं के पास, सुरक्षित की गई रेंज या शीट में बदलाव करने की अनुमति है या नहीं.
canEdit()Booleanइस कुकी से यह तय किया जाता है कि उपयोगकर्ता के पास सुरक्षित की गई रेंज या शीट में बदलाव करने की अनुमति है या नहीं.
getDescription()Stringसुरक्षित की गई रेंज या शीट की जानकारी मिलती है.
getEditors()User[]इस फ़ंक्शन की मदद से, सुरक्षित की गई रेंज या शीट के लिए एडिटर की सूची मिलती है.
getProtectionType()ProtectionTypeइस फ़ील्ड से, सुरक्षित किए गए क्षेत्र का टाइप मिलता है. यह RANGE या SHEET होता है.
getRange()Rangeसुरक्षित की जा रही रेंज मिलती है.
getRangeName()String|nullअगर सुरक्षित की गई रेंज, नाम वाली रेंज से जुड़ी है, तो उसका नाम दिखाता है.
getTargetAudiences()TargetAudience[]इस फ़ंक्शन से, उन टारगेट ऑडियंस के आईडी मिलते हैं जो सुरक्षित की गई रेंज में बदलाव कर सकती हैं.
getUnprotectedRanges()Range[]यह फ़ंक्शन, सुरक्षित की गई किसी शीट में मौजूद असुरक्षित रेंज की एक कलेक्शन दिखाता है.
isWarningOnly()Booleanयह कुकी तय करती है कि सुरक्षित क्षेत्र में "चेतावनी आधारित" सुरक्षा का इस्तेमाल किया जा रहा है या नहीं.
remove()voidइससे रेंज या शीट को असुरक्षित किया जाता है.
removeEditor(emailAddress)Protectionइस फ़ंक्शन का इस्तेमाल करके, सुरक्षित की गई शीट या रेंज के लिए, दिए गए उपयोगकर्ता को एडिटर की सूची से हटाया जा सकता है.
removeEditor(user)Protectionइस फ़ंक्शन का इस्तेमाल करके, सुरक्षित की गई शीट या रेंज के लिए, दिए गए उपयोगकर्ता को एडिटर की सूची से हटाया जा सकता है.
removeEditors(emailAddresses)Protectionयह फ़ंक्शन, सुरक्षित की गई शीट या रेंज के लिए, एडिटर की सूची से उपयोगकर्ताओं के दिए गए ऐरे को हटाता है.
removeTargetAudience(audienceId)Protectionइस फ़ंक्शन का इस्तेमाल करके, सुरक्षित की गई रेंज के एडिटर के तौर पर सेट की गई टारगेट ऑडियंस को हटाया जा सकता है.
setDescription(description)Protectionसुरक्षित की गई रेंज या शीट की जानकारी सेट करता है.
setDomainEdit(editable)Protectionइस विकल्प से यह तय किया जाता है कि स्प्रेडशीट के मालिक डोमेन के सभी उपयोगकर्ताओं के पास, सुरक्षित की गई रेंज या शीट में बदलाव करने की अनुमति है या नहीं.
setNamedRange(namedRange)Protectionइस फ़ंक्शन की मदद से, सुरक्षित की गई रेंज को नाम वाली किसी मौजूदा रेंज से जोड़ा जाता है.
setRange(range)Protectionसुरक्षित की जा रही रेंज को अडजस्ट करता है.
setRangeName(rangeName)Protectionइस फ़ंक्शन की मदद से, सुरक्षित की गई रेंज को नाम वाली किसी मौजूदा रेंज से जोड़ा जाता है.
setUnprotectedRanges(ranges)Protectionसुरक्षित की गई शीट में, रेंज की दी गई ऐरे को असुरक्षित करता है.
setWarningOnly(warningOnly)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());
}

पैरामीटर

नामटाइपब्यौरा
emailAddressStringजिस उपयोगकर्ता को जोड़ना है उसका ईमेल पता.

वापसी का टिकट

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

पैरामीटर

नामटाइपब्यौरा
userUserजोड़े जाने वाले उपयोगकर्ता का प्रतिनिधित्व.

वापसी का टिकट

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

पैरामीटर

नामटाइपब्यौरा
emailAddressesString[]जोड़े जाने वाले उपयोगकर्ताओं के ईमेल पतों की एक कैटगरी.

वापसी का टिकट

Protection — यह ऑब्जेक्ट, सुरक्षा सेटिंग को दिखाता है. इसका इस्तेमाल चेनिंग के लिए किया जाता है.

अनुमति देना

इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट के लिए, इनमें से एक या उससे ज़्यादा स्कोप के साथ अनुमति लेना ज़रूरी है:

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

addTargetAudience(audienceId)

यह फ़ंक्शन, सुरक्षित की गई रेंज के एडिटर के तौर पर, चुनी गई टारगेट ऑडियंस को जोड़ता है.

पैरामीटर

नामटाइपब्यौरा
audienceIdStringजोड़ने के लिए टारगेट ऑडियंस का आईडी.

वापसी का टिकट

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

वापसी का टिकट

Booleantrue अगर स्प्रेडशीट के मालिकाना हक वाले डोमेन के सभी उपयोगकर्ताओं के पास, सुरक्षित की गई रेंज या शीट में बदलाव करने की अनुमति है; 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();
  }
}

वापसी का टिकट

Booleantrue अगर उपयोगकर्ता के पास सुरक्षित की गई रेंज या शीट में बदलाव करने की अनुमति है; 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());

वापसी का टिकट

ProtectionType — संरक्षित क्षेत्र का टाइप, 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 दिखाता है. ध्यान दें कि किसी सुरक्षित रेंज को नामित रेंज से जोड़ने के लिए, स्क्रिप्ट को साफ़ तौर पर setRangeName(rangeName) को कॉल करना होगा. Range से सुरक्षा बनाने के लिए Range.protect() को कॉल करना, उन्हें जोड़ने के लिए काफ़ी नहीं है. ऐसा इसलिए, क्योंकि Range एक नामित रेंज है और setRangeName(rangeName) को कॉल नहीं किया गया है. हालांकि, 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 — सुरक्षित की गई नामित रेंज का नाम या null, अगर सुरक्षित की गई रेंज किसी नामित रेंज से जुड़ी नहीं है

अनुमति देना

इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट के लिए, इनमें से एक या उससे ज़्यादा स्कोप के साथ अनुमति लेना ज़रूरी है:

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

getTargetAudiences()

इस फ़ंक्शन से, उन टारगेट ऑडियंस के आईडी मिलते हैं जो सुरक्षित की गई रेंज में बदलाव कर सकती हैं.

वापसी का टिकट

TargetAudience[] — टारगेट ऑडियंस के आईडी का कलेक्शन.

अनुमति देना

इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट के लिए, इनमें से एक या उससे ज़्यादा स्कोप के साथ अनुमति लेना ज़रूरी है:

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

getUnprotectedRanges()

यह फ़ंक्शन, सुरक्षित की गई किसी शीट में मौजूद असुरक्षित रेंज की एक कलेक्शन दिखाता है. अगर Protection ऑब्जेक्ट, सुरक्षित की गई शीट के बजाय सुरक्षित की गई रेंज से जुड़ा है, तो यह तरीका एक खाली कलेक्शन दिखाता है. सुरक्षा से बाहर रखी गई रेंज बदलने के लिए, setUnprotectedRanges(ranges) का इस्तेमाल करके रेंज का नया कलेक्शन सेट करें. पूरी शीट को फिर से सुरक्षित रखने के लिए, खाली कलेक्शन सेट करें.

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

यह कुकी तय करती है कि सुरक्षित क्षेत्र में "चेतावनी आधारित" सुरक्षा का इस्तेमाल किया जा रहा है या नहीं. चेतावनी के आधार पर सुरक्षा का मतलब है कि हर उपयोगकर्ता उस रेंज में मौजूद डेटा में बदलाव कर सकता है. हालांकि, बदलाव करने पर एक चेतावनी दिखेगी, जिसमें उपयोगकर्ता से बदलाव की पुष्टि करने के लिए कहा जाएगा. डिफ़ॉल्ट रूप से, सुरक्षित की गई रेंज या शीट में चेतावनी नहीं दी जाती है. चेतावनी की स्थिति में बदलने के लिए, 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);

वापसी का टिकट

Booleantrue अगर सुरक्षित की गई रेंज या शीट में सिर्फ़ चेतावनी वाली सुरक्षा का इस्तेमाल किया जा रहा है.

अनुमति देना

इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट के लिए, इनमें से एक या उससे ज़्यादा स्कोप के साथ अनुमति लेना ज़रूरी है:

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

पैरामीटर

नामटाइपब्यौरा
emailAddressStringउस उपयोगकर्ता का ईमेल पता जिसे हटाना है.

वापसी का टिकट

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

पैरामीटर

नामटाइपब्यौरा
userUserउस उपयोगकर्ता का प्रतिनिधित्व जिसे हटाना है.

वापसी का टिकट

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

पैरामीटर

नामटाइपब्यौरा
emailAddressesString[]हटाए जाने वाले उपयोगकर्ताओं के ईमेल पतों की एक कैटगरी.

वापसी का टिकट

Protection — यह ऑब्जेक्ट, सुरक्षा से जुड़ी सेटिंग दिखाता है. इसका इस्तेमाल चेनिंग के लिए किया जाता है

अनुमति देना

इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट के लिए, इनमें से एक या उससे ज़्यादा स्कोप के साथ अनुमति लेना ज़रूरी है:

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

removeTargetAudience(audienceId)

इस फ़ंक्शन का इस्तेमाल करके, सुरक्षित की गई रेंज के एडिटर के तौर पर सेट की गई टारगेट ऑडियंस को हटाया जा सकता है.

पैरामीटर

नामटाइपब्यौरा
audienceIdStringटारगेट ऑडियंस का वह आईडी जिसे हटाना है.

वापसी का टिकट

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

पैरामीटर

नामटाइपब्यौरा
descriptionStringसुरक्षित की गई रेंज या शीट की जानकारी.

वापसी का टिकट

Protection — यह ऑब्जेक्ट, सुरक्षा सेटिंग को दिखाता है. इसका इस्तेमाल चेनिंग के लिए किया जाता है.

अनुमति देना

इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट के लिए, इनमें से एक या उससे ज़्यादा स्कोप के साथ अनुमति लेना ज़रूरी है:

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

setDomainEdit(editable)

इस विकल्प से यह तय किया जाता है कि स्प्रेडशीट के मालिक डोमेन के सभी उपयोगकर्ताओं के पास, सुरक्षित की गई रेंज या शीट में बदलाव करने की अनुमति है या नहीं. ध्यान दें कि जिन उपयोगकर्ताओं के पास बदलाव करने की अनुमति है वे इस सेटिंग के बावजूद, सुरक्षित की गई जगह में बदलाव कर सकते हैं. अगर स्प्रेडशीट किसी Google Workspace डोमेन से जुड़ी नहीं है, तो यह फ़ंक्शन एक अपवाद दिखाता है. इसका मतलब है कि अगर स्प्रेडशीट का मालिकाना हक किसी gmail.com खाते के पास है, तो यह फ़ंक्शन एक अपवाद दिखाता है.

पैरामीटर

नामटाइपब्यौरा
editableBooleantrue अगर स्प्रेडशीट के मालिकाना हक वाले डोमेन के सभी उपयोगकर्ताओं के पास, सुरक्षित की गई रेंज या शीट में बदलाव करने की अनुमति होनी चाहिए; false अगर ऐसा नहीं है.

वापसी का टिकट

Protection — यह ऑब्जेक्ट, सुरक्षा से जुड़ी सेटिंग दिखाता है. इसका इस्तेमाल चेनिंग के लिए किया जाता है

अनुमति देना

इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट के लिए, इनमें से एक या उससे ज़्यादा स्कोप के साथ अनुमति लेना ज़रूरी है:

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

setNamedRange(namedRange)

इस फ़ंक्शन की मदद से, सुरक्षित की गई रेंज को नाम वाली किसी मौजूदा रेंज से जोड़ा जाता है. अगर नामित रेंज, मौजूदा सुरक्षित रेंज से अलग है, तो यह तरीका सुरक्षा को नामित रेंज पर ले जाता है. नाम वाली रेंज, उसी शीट पर होनी चाहिए जिस पर मौजूदा सुरक्षित रेंज है. ध्यान दें कि स्क्रिप्ट को इस तरीके को साफ़ तौर पर कॉल करना होगा, ताकि सुरक्षित की गई रेंज को नाम वाली रेंज से जोड़ा जा सके. Range.protect() को कॉल करके, Range से सुरक्षा बनाने के लिए, setRangeName(rangeName) को कॉल किए बिना, उन्हें जोड़ने के लिए काफ़ी नहीं है. हालांकि, 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());

पैरामीटर

नामटाइपब्यौरा
namedRangeNamedRangeसुरक्षित की गई रेंज से जुड़ी मौजूदा नाम वाली रेंज.

वापसी का टिकट

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

पैरामीटर

नामटाइपब्यौरा
rangeRangeबदलावों से सुरक्षित रखने के लिए नई रेंज.

वापसी का टिकट

Protection — यह ऑब्जेक्ट, सुरक्षा सेटिंग को दिखाता है. इसका इस्तेमाल चेनिंग के लिए किया जाता है.

अनुमति देना

इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट के लिए, इनमें से एक या उससे ज़्यादा स्कोप के साथ अनुमति लेना ज़रूरी है:

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

setRangeName(rangeName)

इस फ़ंक्शन की मदद से, सुरक्षित की गई रेंज को नाम वाली किसी मौजूदा रेंज से जोड़ा जाता है. अगर नामित रेंज, मौजूदा सुरक्षित रेंज से अलग है, तो यह तरीका सुरक्षा को नामित रेंज पर ले जाता है. नाम वाली रेंज, उसी शीट पर होनी चाहिए जिस पर मौजूदा सुरक्षित रेंज है. ध्यान दें कि स्क्रिप्ट को इस तरीके को साफ़ तौर पर कॉल करना होगा, ताकि सुरक्षित की गई रेंज को नाम वाली रेंज से जोड़ा जा सके. Range.protect() को कॉल करके, Range से सुरक्षा बनाने के लिए, setRangeName(rangeName) को कॉल किए बिना, उन्हें जोड़ने के लिए काफ़ी नहीं है. हालांकि, 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.

पैरामीटर

नामटाइपब्यौरा
rangeNameStringसुरक्षित की जाने वाली, नाम वाली रेंज का नाम.

वापसी का टिकट

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

पैरामीटर

नामटाइपब्यौरा
rangesRange[]सुरक्षित की गई शीट में, असुरक्षित रखने के लिए रेंज का कलेक्शन.

वापसी का टिकट

Protection — यह ऑब्जेक्ट, सुरक्षा से जुड़ी सेटिंग दिखाता है. इसका इस्तेमाल चेनिंग के लिए किया जाता है

अनुमति देना

इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट के लिए, इनमें से एक या उससे ज़्यादा स्कोप के साथ अनुमति लेना ज़रूरी है:

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

setWarningOnly(warningOnly)

इससे यह तय होता है कि सुरक्षित की गई यह रेंज, "चेतावनी पर आधारित" सुरक्षा का इस्तेमाल कर रही है या नहीं. चेतावनी के आधार पर सुरक्षा का मतलब है कि हर उपयोगकर्ता, उस रेंज में मौजूद डेटा में बदलाव कर सकता है. हालांकि, बदलाव करने पर एक चेतावनी दिखेगी. इसमें उपयोगकर्ता से बदलाव की पुष्टि करने के लिए कहा जाएगा. डिफ़ॉल्ट रूप से, सुरक्षित की गई रेंज या शीट में चेतावनी नहीं दिखती है. चेतावनी की स्थिति देखने के लिए, 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());

पैरामीटर

नामटाइपब्यौरा
warningOnlyBoolean

वापसी का टिकट

Protection — यह ऑब्जेक्ट, सुरक्षा सेटिंग को दिखाता है. इसका इस्तेमाल चेनिंग के लिए किया जाता है.

अनुमति देना

इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट के लिए, इनमें से एक या उससे ज़्यादा स्कोप के साथ अनुमति लेना ज़रूरी है:

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