Class DocumentTab

DocumentTab

दस्तावेज़ वाला टैब, जिसमें रिच टेक्स्ट के साथ टेबल और सूचियों जैसे एलिमेंट शामिल होते हैं.

Document.getTabs()[tabIndex].asDocumentTab() का इस्तेमाल करके दस्तावेज़ का टैब वापस पाएं.

// Get a specific document tab based on the tab ID.
var documentTab = DocumentApp.openById('abc123456').getTab('t.0').asDocumentTab();

तरीके

तरीकारिटर्न टाइपसंक्षिप्त विवरण
addBookmark(position)Bookmarkदिए गए Position में Bookmark जोड़ता है.
addFooter()FooterSectionअगर कोई टैब फ़ुटर सेक्शन मौजूद नहीं है, तो उसे जोड़ देता है.
addHeader()HeaderSectionअगर कोई टैब हेडर सेक्शन मौजूद नहीं है, तो उसे जोड़ देता है.
addNamedRange(name, range)NamedRangeएक NamedRange जोड़ता है, जो एक Range है, जिसमें इस्तेमाल करने के लिए नाम और आईडी होता है उसे बाद में वापस पाया जा सकता है.
getBody()Bodyटैब के Body को वापस लाता है.
getBookmark(id)Bookmarkदिए गए आईडी के साथ Bookmark लेता है.
getBookmarks()Bookmark[]टैब के सभी Bookmark ऑब्जेक्ट को ऐक्सेस करता है.
getFooter()FooterSectionअगर टैब का फ़ुटर सेक्शन मौजूद है, तो उसे वापस लाया जाता है.
getFootnotes()Footnote[]टैब के मुख्य हिस्से में मौजूद सभी Footnote एलिमेंट हासिल करता है.
getHeader()HeaderSectionअगर टैब का हेडर सेक्शन मौजूद है, तो उसे वापस लाया जाता है.
getNamedRangeById(id)NamedRangeदिए गए आईडी के साथ NamedRange लेता है.
getNamedRanges()NamedRange[]टैब के सभी NamedRange ऑब्जेक्ट को ऐक्सेस करता है.
getNamedRanges(name)NamedRange[]दिए गए नाम के साथ टैब में सभी NamedRange ऑब्जेक्ट को फ़ेच करता है.
newPosition(element, offset)Positionएक नया Position बनाता है, जो किसी टैब में मौजूद किसी जगह का रेफ़रंस होता है. खास एलिमेंट की ज़रूरत होती है.
newRange()RangeBuilderटैब एलिमेंट से Range ऑब्जेक्ट बनाने के लिए इस्तेमाल किया जाने वाला बिल्डर बनाता है.

विस्तृत दस्तावेज़

addBookmark(position)

दिए गए Position में Bookmark जोड़ता है.

// Opens the Docs file by its ID and retrieves the tab with ID 't.0'. If you created your
// script from within a Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the doc ID and the tab ID with your own.
const documentTab = DocumentApp.openById('abc123456').getTab('t.0').asDocumentTab();

// Gets the tab body and adds a paragraph.
const paragraph = documentTab.getBody().appendParagraph('My new paragraph.');

// Creates a position at the first character of the paragraph text.
const position = documentTab.newPosition(paragraph.getChild(0), 0);

// Adds a bookmark at the first character of the paragraph text.
const bookmark = documentTab.addBookmark(position);

// Logs the bookmark ID to the console.
console.log(bookmark.getId());

पैरामीटर

नामटाइपब्यौरा
positionPositionनए बुकमार्क की स्थिति.

वापसी का टिकट

Bookmark — नया बुकमार्क.

अनुमति देना

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

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

addFooter()

अगर कोई टैब फ़ुटर सेक्शन मौजूद नहीं है, तो उसे जोड़ देता है.

// Opens the Docs file by its ID and retrieves the tab with ID 't.0'. If you created your
// script from within a Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the doc ID and the tab ID with your own.
const documentTab = DocumentApp.openById('abc123456').getTab('t.0').asDocumentTab();

// Adds a footer to the tab.
const footer = documentTab.addFooter();

// Sets the footer text to 'This is a footer.'
footer.setText('This is a footer');

वापसी का टिकट

FooterSection — टैब फ़ुटर.

अनुमति देना

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

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

addHeader()

अगर कोई टैब हेडर सेक्शन मौजूद नहीं है, तो उसे जोड़ देता है.

// Opens the Docs file by its ID and retrieves the tab with ID 't.0'. If you created your
// script from within a Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the doc ID and the tab ID with your own.
const documentTab = DocumentApp.openById('abc123456').getTab('t.0').asDocumentTab();

// Adds a header to the tab.
const header = documentTab.addHeader();

// Sets the header text to 'This is a header.'
header.setText('This is a header');

वापसी का टिकट

HeaderSection — टैब हेडर.

अनुमति देना

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

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

addNamedRange(name, range)

एक NamedRange जोड़ता है, जो एक Range है, जिसमें इस्तेमाल करने के लिए नाम और आईडी होता है उसे बाद में वापस पाया जा सकता है. यह ज़रूरी नहीं है कि सभी टैब में नाम यूनीक हों; कई अलग-अलग रेंज में उसी दस्तावेज़ में एक ही नाम हो सकता है, काफ़ी हद तक HTML में एक क्लास की तरह. इसके उलट, आईडी होना चाहिए, जैसे कि एचटीएमएल में कोई आईडी. NamedRange को जोड़ने के बाद, ये काम नहीं किए जा सकते तो आप उसे सिर्फ़ हटा सकते हैं.

इस टैब को ऐक्सेस करने वाली कोई भी स्क्रिप्ट, NamedRange को ऐक्सेस कर सकती है. अनजाने में होने वाली समस्याओं से बचने के लिए स्क्रिप्ट के बीच टकराव होता है, तो रेंज के नामों से पहले किसी यूनीक स्ट्रिंग का इस्तेमाल करें.

// Creates a named range that includes every table in the tab with tab ID 't.0'.
var documentTab = DocumentApp.openById('abc123456').getTab('t.0').asDocumentTab();
var rangeBuilder = documentTab.newRange();
var tables = documentTab.getBody().getTables();
for (var i = 0; i < tables.length; i++) {
  rangeBuilder.addElement(tables[i]);
}
documentTab.addNamedRange('Tab t.0 tables', rangeBuilder.build());

पैरामीटर

नामटाइपब्यौरा
nameStringरेंज का नाम, जिसका यूनीक होना ज़रूरी नहीं है; रेंज के नाम ये होने चाहिए 1 से 256 वर्णों का होना चाहिए.
rangeRangeनाम के साथ जोड़े जाने वाले एलिमेंट की रेंज; यह सीमा कोई खोज नतीजा हो सकती है या फिर newRange() का इस्तेमाल करके मैन्युअल तरीके से बनाई जा सकती है.

वापसी का टिकट

NamedRangeNamedRange.

अनुमति देना

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

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

getBody()

टैब के Body को वापस लाता है.

टैब में अलग-अलग तरह के सेक्शन हो सकते हैं, जैसे कि HeaderSection, FooterSection. किसी टैब के लिए ऐक्टिव सेक्शन Body है.

DocumentTab में एलिमेंट के तरीके, Body को डेलिगेट करते हैं.

// Opens the Docs file by its ID and retrieves the tab with ID 't.0'. If you created your
// script from within a Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the doc ID and the tab ID with your own.
const documentTab = DocumentApp.openById('abc123456').getTab('t.0').asDocumentTab();

// Gets the tab body.
const body = documentTab.getBody();

// Gets the body text and logs it to the console.
console.log(body.getText());

वापसी का टिकट

Body — टैब का मुख्य हिस्सा.

अनुमति देना

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

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

getBookmark(id)

दिए गए आईडी के साथ Bookmark लेता है. अगर इस टैब में ऐसा कोई Bookmark मौजूद नहीं है, तो यह तरीका null दिखाता है.

// Opens the Docs file by its ID and retrieves the tab with ID 't.0'. If you created your
// script from within a Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the doc ID and the tab ID with your own.
const documentTab = DocumentApp.openById('abc123456').getTab('t.0').asDocumentTab();

// Gets the bookmark by its ID.
const bookmark = documentTab.getBookmark('id.xyz654321');

// If the bookmark exists within the tab, logs the character offset of its position to the
// console. Otherwise, logs 'No bookmark exists with the given ID.' to the console.
if (bookmark) {
  console.log(bookmark.getPosition().getOffset());
} else {
  console.log('No bookmark exists with the given ID.');
}

पैरामीटर

नामटाइपब्यौरा
idStringBookmark का आईडी.

वापसी का टिकट

Bookmark — दिए गए आईडी वाला Bookmark या अगर कोई Bookmark नहीं है, तो null यह टैब में मौजूद होता है.

अनुमति देना

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

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

getBookmarks()

टैब के सभी Bookmark ऑब्जेक्ट को ऐक्सेस करता है.

// Opens the Docs file by its ID and retrieves the tab with ID 't.0'. If you created your
// script from within a Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the doc ID and the tab ID with your own.
const documentTab = DocumentApp.openById('abc123456').getTab('t.0').asDocumentTab();

// Gets all of the bookmarks in the tab.
const bookmarks = documentTab.getBookmarks();

// Logs the number of bookmarks in the tab to the console.
console.log(bookmarks.length);

वापसी का टिकट

Bookmark[] — टैब में मौजूद Bookmark ऑब्जेक्ट का कलेक्शन.

अनुमति देना

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

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

getFooter()

अगर टैब का फ़ुटर सेक्शन मौजूद है, तो उसे वापस लाया जाता है.

// Opens the Docs file by its ID and retrieves the tab with ID 't.0'. If you created your
// script from within a Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the doc ID and the tab ID with your own.
const documentTab = DocumentApp.openById('abc123456').getTab('t.0').asDocumentTab();

// Gets the text of the tab's footer and logs it to the console.
console.log(documentTab.getFooter().getText());

वापसी का टिकट

FooterSection — टैब का फ़ुटर.

अनुमति देना

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

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

getFootnotes()

टैब के मुख्य हिस्से में मौजूद सभी Footnote एलिमेंट हासिल करता है.

getFootnotes पर किए जाने वाले कॉल से, टैब के एलिमेंट में गड़बड़ी पैदा होती है. बड़े टैब के लिए, इस तरीके को गैर-ज़रूरी कॉल से बचाएं.

// Opens the Docs file by its ID and retrieves the tab with ID 't.0'. If you created your
// script from within a Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the doc ID and the tab ID with your own.
const documentTab = DocumentApp.openById('abc123456').getTab('t.0').asDocumentTab();

// Gets the first footnote.
const footnote = documentTab.getFootnotes()[0];

// Logs footnote contents to the console.
console.log(footnote.getFootnoteContents().getText());

वापसी का टिकट

Footnote[] — टैब के फ़ुटनोट.

अनुमति देना

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

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

getHeader()

अगर टैब का हेडर सेक्शन मौजूद है, तो उसे वापस लाया जाता है.

// Opens the Docs file by its ID and retrieves the tab with ID 't.0'. If you created your
// script from within a Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the doc ID and the tab ID with your own.
const documentTab = DocumentApp.openById('abc123456').getTab('t.0').asDocumentTab();

// Gets the text of the tab's header and logs it to the console.
console.log(documentTab.getHeader().getText());

वापसी का टिकट

HeaderSection — टैब का हेडर.

अनुमति देना

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

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

getNamedRangeById(id)

दिए गए आईडी के साथ NamedRange लेता है. अगर ऐसा नहीं है, तो यह तरीका null दिखाता है टैब में NamedRange मौजूद है. यह ज़रूरी नहीं है कि नाम अलग-अलग हों, यहां तक कि पूरे टैब पर भी; ऐसा हो सकता है कि एक ही दस्तावेज़ में कई अलग-अलग रेंज का एक ही नाम हो, जैसे एचटीएमएल. इसके उलट, टैब में आईडी, एचटीएमएल के आईडी की तरह ही यूनीक होते हैं.

पैरामीटर

नामटाइपब्यौरा
idStringरेंज का आईडी, जो टैब के अंदर यूनीक होता है.

वापसी का टिकट

NamedRange — दिए गए आईडी के साथ NamedRange या null, अगर ऐसी कोई रेंज मौजूद नहीं है टैब.

अनुमति देना

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

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

getNamedRanges()

टैब के सभी NamedRange ऑब्जेक्ट को ऐक्सेस करता है.

टैब को ऐक्सेस करने वाली कोई भी स्क्रिप्ट, NamedRange को ऐक्सेस कर सकती है. इससे बचने के लिए स्क्रिप्ट के बीच अनचाहे टकराव होते हैं, तो रेंज के नामों से पहले किसी यूनीक स्ट्रिंग का इस्तेमाल करें.

वापसी का टिकट

NamedRange[] — टैब में NamedRange ऑब्जेक्ट का कलेक्शन. इसमें कई आइटम शामिल हो सकते हैं समान नाम वाली रेंज.

अनुमति देना

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

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

getNamedRanges(name)

दिए गए नाम के साथ टैब में सभी NamedRange ऑब्जेक्ट को फ़ेच करता है. नाम ज़रूरी नहीं हैं अपने-आप लागू होता है, यहां तक कि टैब पर भी; ऐसा हो सकता है कि एक ही दस्तावेज़ में मौजूद कई अलग-अलग रेंज एक ही हों नाम, काफ़ी हद तक HTML में एक क्लास की तरह है. इसके उलट, टैब के अंदर आईडी यूनीक होते हैं, जैसे कि एचटीएमएल.

टैब को ऐक्सेस करने वाली कोई भी स्क्रिप्ट, NamedRange को ऐक्सेस कर सकती है. इससे बचने के लिए स्क्रिप्ट के बीच अनचाहे टकराव होते हैं, तो रेंज के नामों से पहले किसी यूनीक स्ट्रिंग का इस्तेमाल करें.

पैरामीटर

नामटाइपब्यौरा
nameStringरेंज का नाम, जो ज़रूरी नहीं है कि यूनीक हो.

वापसी का टिकट

NamedRange[] — दिए गए नाम के साथ टैब में मौजूद NamedRange ऑब्जेक्ट का कलेक्शन.

अनुमति देना

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

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

newPosition(element, offset)

एक नया Position बनाता है, जो किसी टैब में मौजूद किसी जगह का रेफ़रंस होता है. खास एलिमेंट की ज़रूरत होती है. अन्य इस्तेमाल के साथ, उपयोगकर्ता के कर्सर को Position के तौर पर दिखाया जाता है.

// Append a paragraph, then place the user's cursor after the first word of the new paragraph.
var doc = DocumentApp.openById('abc123456');
var documentTab = doc.getTab('t.0').asDocumentTab();
var paragraph = documentTab.getBody().appendParagraph('My new paragraph.');
var position = documentTab.newPosition(paragraph.getChild(0), 2);
doc.setCursor(position);

पैरामीटर

नामटाइपब्यौरा
elementElementवह एलिमेंट जिसमें बनाए गए नए Position को शामिल किया गया है; यह होना चाहिए Text एलिमेंट या Paragraph जैसे कंटेनर एलिमेंट.
offsetIntegerText एलिमेंट के लिए, Position से पहले के वर्णों की संख्या; अन्य एलिमेंट के लिए, Position से पहले चाइल्ड एलिमेंट की संख्या एक ही कंटेनर एलिमेंट.

वापसी का टिकट

Position — नया Position.

अनुमति देना

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

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

newRange()

टैब एलिमेंट से Range ऑब्जेक्ट बनाने के लिए इस्तेमाल किया जाने वाला बिल्डर बनाता है.

// Change the user's selection to a range that includes every table in the tab.
var doc = DocumentApp.openById('abc123456');
var documentTab = doc.getTab('t.0').asDocumentTab();
var rangeBuilder = documentTab.newRange();
var tables = documentTab.getBody().getTables();
for (var i = 0; i < tables.length; i++) {
  rangeBuilder.addElement(tables[i]);
}
doc.setSelection(rangeBuilder.build());

वापसी का टिकट

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

अनुमति देना

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

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