Class SpreadsheetApp

SpreadsheetApp

Google Sheets की फ़ाइलें ऐक्सेस करें और बनाएं. यह क्लास, स्प्रेडशीट सेवा के लिए पैरंट क्लास है.

प्रॉपर्टी

प्रॉपर्टीTypeब्यौरा
AutoFillSeriesAutoFillSeriesअपने-आप भरी गई वैल्यू को कैलकुलेट करने के लिए, इस्तेमाल की जाने वाली सीरीज़ के टाइप की सूची.
BandingThemeBandingThemeसंभावित बैंडिंग थीम की सूची.
BooleanCriteriaBooleanCriteriaकंडिशनल फ़ॉर्मैटिंग के बूलियन मानदंड की गिनती.
BorderStyleBorderStyleRange पर बॉर्डर सेट करने के लिए मान्य स्टाइल की गिनती.
ColorTypeColorTypeसंभावित रंग के प्रकारों की सूची.
CopyPasteTypeCopyPasteTypeसंभावित पेस्ट टाइप की सूची.
DataExecutionErrorCodeDataExecutionErrorCodeडेटा एक्ज़ीक्यूट करने से जुड़ी संभावित गड़बड़ी कोड की गिनती.
DataExecutionStateDataExecutionStateडेटा लागू होने की संभावित स्थितियों की गिनती.
DataSourceParameterTypeDataSourceParameterTypeडेटा सोर्स के संभावित पैरामीटर टाइप की गिनती.
DataSourceRefreshScopeDataSourceRefreshScopeसंभावित डेटा सोर्स के रीफ़्रेश होने वाले स्कोप की गिनती.
DataSourceTypeDataSourceTypeसंभावित डेटा सोर्स टाइप की सूची.
DataValidationCriteriaDataValidationCriteriaडेटा की पुष्टि करने की उस ज़रूरी शर्त को दिखाने वाला इन्युमेशन जिसे किसी रेंज पर सेट किया जा सकता है.
DateTimeGroupingRuleTypeDateTimeGroupingRuleTypeतारीख और समय के ग्रुप के नियम की गिनती.
DeveloperMetadataLocationTypeDeveloperMetadataLocationTypeडेवलपर मेटाडेटा की संभावित लोकेशन टाइप की सूची.
DeveloperMetadataVisibilityDeveloperMetadataVisibilityडेवलपर मेटाडेटा के दिखने की संभावित गड़बड़ियों की सूची.
DimensionDimensionस्प्रेडशीट के संभावित डाइमेंशन की गिनती.
DirectionDirectionऐरो बटन का इस्तेमाल करके, स्प्रेडशीट में उन निर्देशों की सूची जिन्हें कोई व्यक्ति अलग-अलग जगह पर ले जा सकता है.
FrequencyTypeFrequencyTypeसंभावित फ़्रीक्वेंसी टाइप की गिनती.
GroupControlTogglePositionGroupControlTogglePositionउन स्थितियों की गिनती जिसमें ग्रुप कंट्रोल टॉगल हो सकता है.
InterpolationTypeInterpolationTypeकंडिशनल फ़ॉर्मैट ग्रेडिएंट इंटरपोलेशन टाइप की गिनती.
PivotTableSummarizeFunctionPivotTableSummarizeFunctionपिवट टेबल में वैल्यू की खास जानकारी देने के लिए इस्तेमाल किए जा सकने वाले फ़ंक्शन की गिनती.
PivotValueDisplayTypePivotValueDisplayTypeपिवट वैल्यू को दिखाने के तरीकों की जानकारी.
ProtectionTypeProtectionTypeस्प्रेडशीट के उन हिस्सों को दिखाने वाला एन्युमेशन जिन्हें बदलाव करने से सुरक्षित किया जा सकता है.
RecalculationIntervalRecalculationIntervalस्प्रेडशीट की रीकैलकुलेशन प्रोसेस में इस्तेमाल किए जा सकने वाले संभावित इंटरवल की गिनती.
RelativeDateRelativeDateतारीख के आधार पर BooleanCriteria में इस्तेमाल की जाने वाली वैल्यू का हिसाब लगाने के लिए, मिलती-जुलती तारीख के विकल्पों की गिनती.
SheetTypeSheetTypeस्प्रेडशीट में मौजूद अलग-अलग तरह की शीट की सूची.
SortOrderSortOrderक्रम से लगाने की गिनती.
TextDirectionTextDirectionमान्य टेक्स्ट निर्देशों की गिनती.
TextToColumnsDelimiterTextToColumnsDelimiterटेक्स्ट को कॉलम में बांटने के लिए, प्रीसेट डेलिमिटर की गिनती.
ThemeColorTypeThemeColorTypeथीम के संभावित रंग के टाइप की सूची.
ValueTypeValueTypeस्प्रेडशीट सेवा की रेंज क्लास से, Range.getValue() और Range.getValues() से मिली वैल्यू के टाइप की गिनती. नीचे दी गई गिनती की वैल्यू Number, Boolean, Date या String के अलावा हैं.
WrapStrategyWrapStrategyसेल रैप करने के लिए इस्तेमाल की जाने वाली रणनीतियों की गिनती.

तरीके

तरीकारिटर्न टाइपसंक्षिप्त विवरण
create(name)Spreadsheetदिए गए नाम से एक नई स्प्रेडशीट बनाता है.
create(name, rows, columns)Spreadsheetदिए गए नाम और पंक्तियों और कॉलम की तय संख्या के साथ एक नई स्प्रेडशीट बनाता है.
enableAllDataSourcesExecution()voidसभी तरह के डेटा सोर्स के लिए, डेटा एक्ज़ीक्यूशन की सुविधा चालू करता है.
enableBigQueryExecution()voidBigQuery डेटा सोर्स के लिए, डेटा एक्ज़ीक्यूशन चालू करता है.
flush()voidउन सभी स्प्रेडशीट पर लागू होता है जिन्हें मंज़ूरी मिलना बाकी है.
getActive()Spreadsheetमौजूदा समय में चालू स्प्रेडशीट दिखाता है. अगर कोई स्प्रेडशीट नहीं है, तो null दिखाता है.
getActiveRange()Rangeचालू शीट में चुनी गई रेंज दिखाता है. अगर कोई चालू रेंज नहीं है, तो null दिखाता है.
getActiveRangeList()RangeListचालू शीट में चालू रेंज की सूची दिखाता है या अगर कोई रेंज नहीं चुनी गई है, तो null दिखाता है.
getActiveSheet()Sheetऐक्टिव शीट को स्प्रेडशीट में दिखाता है.
getActiveSpreadsheet()Spreadsheetमौजूदा समय में चालू स्प्रेडशीट दिखाता है. अगर कोई स्प्रेडशीट नहीं है, तो null दिखाता है.
getCurrentCell()Rangeसक्रिय शीट की किसी एक सक्रिय रेंज में चुनी गई मौजूदा (हाइलाइट की गई) सेल दिखाता है या अगर कोई मौजूदा सेल नहीं है, तो null दिखाता है.
getSelection()Selectionस्प्रेडशीट में मौजूदा Selection दिखाता है.
getUi()Uiस्प्रेडशीट के यूज़र इंटरफ़ेस एनवायरमेंट का इंस्टेंस दिखाता है, जिससे स्क्रिप्ट को मेन्यू, डायलॉग, और साइडबार जैसी सुविधाएं जोड़ने की अनुमति मिलती है.
newCellImage()CellImageBuilderCellImage के लिए बिल्डर बनाता है.
newColor()ColorBuilderColor के लिए बिल्डर बनाता है.
newConditionalFormatRule()ConditionalFormatRuleBuilderकंडिशनल फ़ॉर्मैटिंग के नियम के लिए बिल्डर बनाता है.
newDataSourceSpec()DataSourceSpecBuilderDataSourceSpec के लिए बिल्डर बनाता है.
newDataValidation()DataValidationBuilderडेटा की पुष्टि करने के नियम के लिए बिल्डर बनाता है.
newFilterCriteria()FilterCriteriaBuilderFilterCriteria के लिए बिल्डर बनाता है.
newRichTextValue()RichTextValueBuilderरिच टेक्स्ट वैल्यू के लिए बिल्डर बनाता है.
newTextStyle()TextStyleBuilderटेक्स्ट स्टाइल के लिए बिल्डर बनाता है.
open(file)Spreadsheetवह स्प्रेडशीट खोलता है जो दिए गए फ़ाइल ऑब्जेक्ट से संबंधित होती है.
openById(id)Spreadsheetदिए गए आईडी वाली स्प्रेडशीट खोलता है.
openByUrl(url)Spreadsheetदिए गए यूआरएल वाली स्प्रेडशीट खोलता है.
setActiveRange(range)Rangeतय की गई रेंज को active range के तौर पर सेट करता है. साथ ही, रेंज में सबसे ऊपर बाईं ओर मौजूद सेल को current cell के तौर पर सेट करता है.
setActiveRangeList(rangeList)RangeListरेंज की तय सूची को active ranges के तौर पर सेट करता है.
setActiveSheet(sheet)Sheetऐक्टिव शीट को स्प्रेडशीट में सेट करता है.
setActiveSheet(sheet, restoreSelection)Sheetचालू शीट को स्प्रेडशीट में सेट करता है. साथ ही, उस शीट में सबसे हाल के वर्शन को वापस लाने का विकल्प भी देता है.
setActiveSpreadsheet(newActiveSpreadsheet)voidचालू स्प्रेडशीट सेट करता है.
setCurrentCell(cell)Rangeबताए गए सेल को current cell के तौर पर सेट करता है.

ज़्यादा जानकारी के साथ दस्तावेज़

create(name)

दिए गए नाम से एक नई स्प्रेडशीट बनाता है.

// The code below creates a new spreadsheet "Finances" and logs the URL for it
var ssNew = SpreadsheetApp.create("Finances");
Logger.log(ssNew.getUrl());

पैरामीटर

नामTypeब्यौरा
nameStringस्प्रेडशीट का नाम.

रिटर्न

Spreadsheet — एक नई स्प्रेडशीट

अनुमति देना

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

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

create(name, rows, columns)

दिए गए नाम और पंक्तियों और कॉलम की तय संख्या के साथ एक नई स्प्रेडशीट बनाता है.

// The code below creates a new spreadsheet "Finances" with 50 rows and 5 columns and logs the
// URL for it
var ssNew = SpreadsheetApp.create("Finances", 50, 5);
Logger.log(ssNew.getUrl());

पैरामीटर

नामTypeब्यौरा
nameStringस्प्रेडशीट का नाम.
rowsIntegerस्प्रेडशीट में पंक्तियों की संख्या.
columnsIntegerस्प्रेडशीट में कॉलम की संख्या.

रिटर्न

Spreadsheet — एक नई स्प्रेडशीट

अनुमति देना

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

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

enableAllDataSourcesExecution()

सभी तरह के डेटा सोर्स के लिए, डेटा एक्ज़ीक्यूशन की सुविधा चालू करता है.

डेटा सोर्स का टाइप चालू न होने पर, डेटा चलाने पर अपवाद मिलता है. सभी डेटा सोर्स टाइप के लिए, डेटा एक्ज़ीक्यूशन चालू करने के लिए यह तरीका अपनाएं.

// Turns data execution on for all types of data sources.
SpreadsheetApp.enableAllDataSourcesExecution();

// Opens the spreadsheet file by its ID. If you created your script from a Google Sheets file,
// use SpreadsheetApp.getActiveSpreadsheet().
// TODO(developer): Replace the ID with your own.
const ss = SpreadsheetApp.openById('abc123456');

// Gets the first data source sheet in the spreadsheet and refreshes the data.
ss.getDataSourceSheets()[0].refreshData();

अनुमति देना

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

  • https://www.googleapis.com/auth/bigquery.readonly

enableBigQueryExecution()

BigQuery डेटा सोर्स के लिए, डेटा एक्ज़ीक्यूशन चालू करता है.

इस सुविधा के चालू न होने पर, BigQuery के डेटा सोर्स के लिए डेटा एक्ज़िक्यूट होने पर अपवाद दिखता है.

// Turns data execution on for BigQuery data sources.
SpreadsheetApp.enableBigQueryExecution();

// Opens the spreadsheet file by its ID. If you created your script from a Google Sheets file,
// use SpreadsheetApp.getActiveSpreadsheet().
// TODO(developer): Replace the ID with your own.
const ss = SpreadsheetApp.openById('abc123456');

// Gets the first data source sheet in the spreadsheet and refreshes the BigQuery data.
ss.getDataSourceSheets()[0].refreshData();

अनुमति देना

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

  • https://www.googleapis.com/auth/bigquery.readonly

flush()

उन सभी स्प्रेडशीट पर लागू होता है जिन्हें मंज़ूरी मिलना बाकी है.

कभी-कभी स्प्रेडशीट ऑपरेशन एक साथ बंडल किए जाते हैं, ताकि परफ़ॉर्मेंस को बेहतर बनाया जा सके, जैसे कि Range.getValue() पर कई कॉल करने पर. हालांकि, कभी-कभी आप यह पक्का करना चाहें कि सभी बचे हुए बदलाव तुरंत कर दिए जाएं. उदाहरण के लिए, स्क्रिप्ट के एक्ज़ीक्यूट होते समय उपयोगकर्ताओं का डेटा दिखाना.

// The code below changes the background color of cells A1 and B1 twenty times. You should be
// able to see the updates live in the spreadsheet. If flush() is not called, the updates may
// be applied live or may all be applied at once when the script completes.
function colors() {
  var sheet = SpreadsheetApp.getActiveSheet();
  for (var i = 0; i < 20; i++) {
    if ((i % 2) == 0) {
      sheet.getRange('A1').setBackground('green');
      sheet.getRange('B1').setBackground('red');
    } else {
      sheet.getRange('A1').setBackground('red');
      sheet.getRange('B1').setBackground('green');
    }
    SpreadsheetApp.flush();
  }
}

getActive()

मौजूदा समय में चालू स्प्रेडशीट दिखाता है. अगर कोई स्प्रेडशीट नहीं है, तो null दिखाता है.

स्प्रेडशीट के संदर्भ में चलाए जाने वाले फ़ंक्शन इस फ़ंक्शन को कॉल करके, उससे जुड़े स्प्रेडशीट ऑब्जेक्ट का रेफ़रंस पा सकते हैं.

// The code below logs the URL for the active spreadsheet.
Logger.log(SpreadsheetApp.getActive().getUrl());

रिटर्न

Spreadsheet — चालू स्प्रेडशीट ऑब्जेक्ट

अनुमति देना

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

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

getActiveRange()

चालू शीट में चुनी गई रेंज दिखाता है. अगर कोई चालू रेंज नहीं है, तो null दिखाता है. अगर एक से ज़्यादा रेंज चुनी जाती हैं, तो यह तरीका सिर्फ़ चुनी गई पिछली रेंज दिखाता है.

आम तौर पर, इसका मतलब उस रेंज से होता है जिसे उपयोगकर्ता ने सक्रिय शीट में चुना है. हालांकि, कस्टम फ़ंक्शन में इसका मतलब उस सेल से है जिसका सक्रिय तौर पर फिर से हिसाब लगाया जा रहा है.

// The code below logs the background color for the active range.
var colorObject = SpreadsheetApp.getActiveRange().getBackgroundObject();
// Assume the color has ColorType.RGB.
Logger.log(colorObject.asRgbColor().asHexString());

रिटर्न

Range — सक्रिय रेंज.

अनुमति देना

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

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

getActiveRangeList()

चालू शीट में चालू रेंज की सूची दिखाता है या अगर कोई रेंज नहीं चुनी गई है, तो null दिखाता है. हाइलाइट की गई मौजूदा सेल वाली चालू रेंज को सूची में सबसे आखिर में रखा जाता है.

अगर सिर्फ़ एक रेंज चुनी जाती है, तो यह getActiveRange() कॉल की तरह काम करता है.

// Returns the list of active ranges.
var rangeList = SpreadsheetApp.getActiveRangeList();

रिटर्न

RangeList — चालू रेंज की सूची

अनुमति देना

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

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

getActiveSheet()

ऐक्टिव शीट को स्प्रेडशीट में दिखाता है.

स्प्रेडशीट में चालू शीट वह शीट होती है जो स्प्रेडशीट यूज़र इंटरफ़ेस (यूआई) में दिख रही है.

// The code below logs the name of the active sheet.
Logger.log(SpreadsheetApp.getActiveSheet().getName());

रिटर्न

Sheet — चालू शीट ऑब्जेक्ट

अनुमति देना

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

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

getActiveSpreadsheet()

मौजूदा समय में चालू स्प्रेडशीट दिखाता है. अगर कोई स्प्रेडशीट नहीं है, तो null दिखाता है.

स्प्रेडशीट के संदर्भ में चलाए जाने वाले फ़ंक्शन, इस फ़ंक्शन को कॉल करके उससे जुड़े Spreadsheet ऑब्जेक्ट का रेफ़रंस पा सकते हैं.

// The code below logs the URL for the active spreadsheet.
Logger.log(SpreadsheetApp.getActiveSpreadsheet().getUrl());

रिटर्न

Spreadsheet — चालू स्प्रेडशीट ऑब्जेक्ट

अनुमति देना

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

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

getCurrentCell()

सक्रिय शीट की किसी एक सक्रिय रेंज में चुनी गई मौजूदा (हाइलाइट की गई) सेल दिखाता है या अगर कोई मौजूदा सेल नहीं है, तो null दिखाता है.

// Returns the current highlighted cell in the one of the active ranges.
var currentCell = SpreadsheetApp.getCurrentCell();

रिटर्न

Range — मौजूदा सेल

अनुमति देना

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

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

getSelection()

स्प्रेडशीट में मौजूदा Selection दिखाता है.

var selection = SpreadsheetApp.getSelection();
var currentCell = selection.getCurrentCell();

रिटर्न

Selection — चुनी गई मौजूदा तारीख

अनुमति देना

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

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

getUi()

स्प्रेडशीट के यूज़र इंटरफ़ेस एनवायरमेंट का इंस्टेंस दिखाता है, जिससे स्क्रिप्ट को मेन्यू, डायलॉग, और साइडबार जैसी सुविधाएं जोड़ने की अनुमति मिलती है. स्क्रिप्ट सिर्फ़ किसी खुली हुई स्प्रेडशीट के मौजूदा इंस्टेंस के लिए यूज़र इंटरफ़ेस (यूआई) के साथ इंटरैक्ट कर सकती है. यह सिर्फ़ तब इंटरैक्ट कर सकती है, जब स्क्रिप्ट स्प्रेडशीट से जुड़ी हो. ज़्यादा जानकारी के लिए, मेन्यू और डायलॉग और साइडबार की गाइड देखें.

// Add a custom menu to the active spreadsheet, including a separator and a sub-menu.
function onOpen(e) {
  SpreadsheetApp.getUi()
      .createMenu('My Menu')
      .addItem('My menu item', 'myFunction')
      .addSeparator()
      .addSubMenu(SpreadsheetApp.getUi().createMenu('My sub-menu')
          .addItem('One sub-menu item', 'mySecondFunction')
          .addItem('Another sub-menu item', 'myThirdFunction'))
      .addToUi();
}

रिटर्न

Ui — इस स्प्रेडशीट के यूज़र इंटरफ़ेस एनवायरमेंट का इंस्टेंस


newCellImage()

CellImage के लिए बिल्डर बनाता है.

// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets cell A1 on Sheet1.
const range = sheet.getRange('A1');

// Builds an image using a source URL.
const cellImage = SpreadsheetApp.newCellImage()
  .setSourceUrl('https://www.gstatic.com/images/branding/productlogos/apps_script/v10/web-64dp/logo_apps_script_color_1x_web_64dp.png')
  .build();

// Sets the image in cell A1.
range.setValue(cellImage);

रिटर्न

CellImageBuilder — नया बिल्डर.


newColor()

Color के लिए बिल्डर बनाता है.

var rgbColor = SpreadsheetApp.newColor().setRgbColor("#FF0000").build();

रिटर्न

ColorBuilder — नया बिल्डर.


newConditionalFormatRule()

कंडिशनल फ़ॉर्मैटिंग के नियम के लिए बिल्डर बनाता है.

// Adds a conditional format rule to a sheet that causes all cells in range A1:B3 to turn red
// if they contain a number between 1 and 10.
var sheet = SpreadsheetApp.getActive().getActiveSheet();
var range = sheet.getRange('A1:B3');
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenNumberBetween(1, 10)
    .setBackground("#FF0000")
    .setRanges([range])
    .build()
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

रिटर्न

ConditionalFormatRuleBuilder — नया बिल्डर.


newDataSourceSpec()

DataSourceSpec के लिए बिल्डर बनाता है.

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

// Enables BigQuery.
SpreadsheetApp.enableBigQueryExecution();

// Builds a data source specification.
// TODO (developer): Update the project ID to your own Google Cloud project ID.
const dataSourceSpec = SpreadsheetApp.newDataSourceSpec()
  .asBigQuery()
  .setProjectId('project-id-1')
  .setTableProjectId('bigquery-public-data')
  .setDatasetId('ncaa_basketball')
  .setTableId('mbb_historical_teams_games')
  .build();

// Adds the data source and its data to the spreadsheet.
ss.insertDataSourceSheet(dataSourceSpec);

रिटर्न

DataSourceSpecBuilder — नया बिल्डर.


newDataValidation()

डेटा की पुष्टि करने के नियम के लिए बिल्डर बनाता है.

var cell = SpreadsheetApp.getActive().getRange('A1');
var rule = SpreadsheetApp.newDataValidation()
    .requireNumberBetween(1, 100)
    .setAllowInvalid(false)
    .setHelpText('Number must be between 1 and 100.')
    .build();
cell.setDataValidation(rule);

रिटर्न

DataValidationBuilder — नया बिल्डर.


newFilterCriteria()

FilterCriteria के लिए बिल्डर बनाता है.

// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Sets the range to A1:D20.
const range = sheet.getRange('A1:D20');

// Creates a filter and applies it to the specified range.
range.createFilter();

// Gets the current filter for the range and creates filter criteria that only shows cells
// that aren't empty.
const filter = range.getFilter();
const criteria = SpreadsheetApp.newFilterCriteria().whenCellNotEmpty().build();

// Sets the criteria to  column C.
filter.setColumnFilterCriteria(3, criteria);

रिटर्न

FilterCriteriaBuilder — नया बिल्डर


newRichTextValue()

रिच टेक्स्ट वैल्यू के लिए बिल्डर बनाता है.

// Sets cell A1 to have the text "Hello world", with "Hello" bolded.
var cell = SpreadsheetApp.getActive().getRange('A1');
var bold = SpreadsheetApp.newTextStyle().setBold(true).build();
var value = SpreadsheetApp.newRichTextValue()
    .setText("Hello world")
    .setTextStyle(0, 5, bold)
    .build();
cell.setRichTextValue(value);

रिटर्न

RichTextValueBuilder — नया बिल्डर.


newTextStyle()

टेक्स्ट स्टाइल के लिए बिल्डर बनाता है.

// Sets range A1:B3 to have red, size 22, bolded, underlined text.
var range = SpreadsheetApp.getActive().getRange('A1:B3');
var style = SpreadsheetApp.newTextStyle()
    .setForegroundColor("red")
    .setFontSize(22)
    .setBold(true)
    .setUnderline(true)
    .build();
range.setTextStyle(style);

रिटर्न

TextStyleBuilder — नया बिल्डर.


open(file)

वह स्प्रेडशीट खोलता है जो दिए गए फ़ाइल ऑब्जेक्ट से संबंधित होती है.

// Get any starred spreadsheets from Google Drive, then open the spreadsheets and log the name
// of the first sheet within each spreadsheet.
var files = DriveApp.searchFiles(
    'starred = true and mimeType = "' + MimeType.GOOGLE_SHEETS + '"');
while (files.hasNext()) {
  var spreadsheet = SpreadsheetApp.open(files.next());
  var sheet = spreadsheet.getSheets()[0];
  Logger.log(sheet.getName());
}

पैरामीटर

नामTypeब्यौरा
fileFileवह फ़ाइल खोलें जिसे खोलना है.

रिटर्न

Spreadsheet — स्प्रेडशीट

अनुमति देना

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

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

openById(id)

दिए गए आईडी वाली स्प्रेडशीट खोलता है. स्प्रेडशीट आईडी को उसके यूआरएल से लिया जा सकता है. उदाहरण के लिए, यूआरएल https://docs.google.com/spreadsheets/d/abc1234567/edit#gid=0 में स्प्रेडशीट आईडी "abc1234567" है.

// The code below opens a spreadsheet using its ID and logs the name for it.
// Note that the spreadsheet is NOT physically opened on the client side.
// It is opened on the server only (for modification by the script).
var ss = SpreadsheetApp.openById("abc1234567");
Logger.log(ss.getName());

पैरामीटर

नामTypeब्यौरा
idStringस्प्रेडशीट के लिए यूनीक आइडेंटिफ़ायर.

रिटर्न

Spreadsheet — दिए गए आईडी वाला स्प्रेडशीट ऑब्जेक्ट

अनुमति देना

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

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

openByUrl(url)

दिए गए यूआरएल वाली स्प्रेडशीट खोलता है. अगर यूआरएल मौजूद नहीं है या उपयोगकर्ता को उसे ऐक्सेस करने की अनुमति नहीं है, तो स्क्रिप्टिंग अपवाद को फेंकता है.

// Opens a spreadsheet by its URL and logs its name.
// Note that the spreadsheet doesn't physically open on the client side.
// It opens on the server only (for modification by the script).
var ss = SpreadsheetApp.openByUrl(
    'https://docs.google.com/spreadsheets/d/abc1234567/edit');
console.log(ss.getName());

पैरामीटर

नामTypeब्यौरा
urlStringस्प्रेडशीट का यूआरएल.

रिटर्न

Spreadsheet — दिए गए यूआरएल वाला स्प्रेडशीट ऑब्जेक्ट.

अनुमति देना

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

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

setActiveRange(range)

तय की गई रेंज को active range के तौर पर सेट करता है. साथ ही, रेंज में सबसे ऊपर बाईं ओर मौजूद सेल को current cell के तौर पर सेट करता है.

स्प्रेडशीट का यूज़र इंटरफ़ेस (यूआई), वह शीट दिखाता है जिसमें चुनी गई रेंज शामिल है और चुनी गई रेंज में तय की गई सेल चुनता है.

// The code below sets range C1:D4 in the first sheet as the active range.
var range = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0].getRange('C1:D4');
SpreadsheetApp.setActiveRange(range);

var selection = SpreadsheetApp.getSelection();
// Current cell: C1
var currentCell = selection.getCurrentCell();
// Active Range: C1:D4
var activeRange = selection.getActiveRange();

पैरामीटर

नामTypeब्यौरा
rangeRangeसक्रिय रेंज बनाने के लिए रेंज.

रिटर्न

Range — चालू नई रेंज


setActiveRangeList(rangeList)

रेंज की तय सूची को active ranges के तौर पर सेट करता है. सूची में आखिरी रेंज को active range के तौर पर सेट किया गया है.

// The code below sets ranges [D4, B2:C4] in the active sheet as the active ranges.
var rangeList = SpreadsheetApp.getActiveSheet().getRanges(['D4', 'B2:C4']);
SpreadsheetApp.setActiveRangeList(rangeList);

var selection = SpreadsheetApp.getSelection();
// Current cell: B2
var currentCell = selection.getCurrentCell();
// Active range: B2:C4
var activeRange = selection.getActiveRange();
// Active range list: [D4, B2:C4]
var activeRangeList = selection.getActiveRangeList();

पैरामीटर

नामTypeब्यौरा
rangeListRangeListचुनी जाने वाली रेंज की सूची.

रिटर्न

RangeList — चुनी गई नई रेंज की सूची

अनुमति देना

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

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

setActiveSheet(sheet)

ऐक्टिव शीट को स्प्रेडशीट में सेट करता है. Google Sheets का यूज़र इंटरफ़ेस (यूआई), चुनी गई शीट को तब तक दिखाता है, जब तक कि वह शीट किसी दूसरी स्प्रेडशीट से संबंधित न हो.

// The code below makes the 2nd sheet active in the active spreadsheet.
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
SpreadsheetApp.setActiveSheet(spreadsheet.getSheets()[1]);

पैरामीटर

नामTypeब्यौरा
sheetSheetनई चालू शीट.

रिटर्न

Sheet — वह शीट जिसे नई चालू शीट बनाई गई है


setActiveSheet(sheet, restoreSelection)

चालू शीट को स्प्रेडशीट में सेट करता है. साथ ही, उस शीट में सबसे हाल के वर्शन को वापस लाने का विकल्प भी देता है. Google Sheets का यूज़र इंटरफ़ेस (यूआई), चुनी गई शीट को तब तक दिखाता है, जब तक कि वह शीट किसी दूसरी स्प्रेडशीट से संबंधित न हो.

var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var firstSheet = spreadsheet.getSheets()[0];
var secondSheet = spreadsheet.getSheets()[1];
// Set the first sheet as the active sheet and select the range D4:F4.
spreadsheet.setActiveSheet(firstSheet).getRange('D4:F4').activate();

// Switch to the second sheet to do some work.
spreadsheet.setActiveSheet(secondSheet);
// Switch back to first sheet, and restore its selection.
spreadsheet.setActiveSheet(firstSheet, true);

// The selection of first sheet is restored, and it logs D4:F4
var range = spreadsheet.getActiveSheet().getSelection().getActiveRange();
Logger.log(range.getA1Notation());

पैरामीटर

नामTypeब्यौरा
sheetSheetनई चालू शीट.
restoreSelectionBooleanअगर true, नई शीट के चालू होने पर, चुनी गई नई शीट को फिर से चुना जाता है, तो नई शीट चालू हो जाती है. false होने पर, चुनी गई मौजूदा शीट में बदलाव किए बिना नई शीट चालू हो जाती है.

रिटर्न

Sheet — नई चालू शीट

अनुमति देना

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

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

setActiveSpreadsheet(newActiveSpreadsheet)

चालू स्प्रेडशीट सेट करता है.

// The code below makes the spreadsheet with key "1234567890" the active spreadsheet
var ss = SpreadsheetApp.openById("1234567890");
SpreadsheetApp.setActiveSpreadsheet(ss);

पैरामीटर

नामTypeब्यौरा
newActiveSpreadsheetSpreadsheetसक्रिय स्प्रैडशीट बनाई जाने वाली स्प्रैडशीट.

setCurrentCell(cell)

बताए गए सेल को current cell के तौर पर सेट करता है.

अगर कोई सेल पहले से चुनी गई किसी रेंज में मौजूद है, तो वह रेंज मौजूदा सेल के तौर पर सेल वाली सक्रिय रेंज बन जाती है.

अगर चुना गया सेल किसी भी चुनी गई रेंज में मौजूद नहीं है, तो मौजूदा सेल को हटा दिया जाता है और सेल, मौजूदा सेल और सक्रिय रेंज बन जाती है.

ध्यान दें: दिए गए Range में एक सेल होना चाहिए. ऐसा न होने पर, यह एक अपवाद है.

// The code below sets the cell B5 in the first sheet as the current cell.
var cell = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0].getRange('B5');
SpreadsheetApp.setCurrentCell(cell);

var selection = SpreadsheetApp.getSelection();
// Current cell: B5
var currentCell = selection.getCurrentCell();

पैरामीटर

नामTypeब्यौरा
cellRangeमौजूदा सेल के तौर पर सेट किया जाने वाला सेल.

रिटर्न

Range — नया सेट किया गया मौजूदा सेल

अनुमति देना

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

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