Class DocumentTab

DocumentTab

Zengin metinlerin yanı sıra tablo ve liste gibi öğeleri içeren bir doküman sekmesi.

Document.getTabs()[tabIndex].asDocumentTab() kullanarak bir doküman sekmesi alın.

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

Yöntemler

YöntemDönüş türüKısa açıklama
addBookmark(position)BookmarkBelirtilen Position için bir Bookmark ekler.
addFooter()FooterSectionYoksa sekme altbilgisi bölümü ekler.
addHeader()HeaderSectionYoksa, sekme üstbilgisi bölümü ekler.
addNamedRange(name, range)NamedRangeŞunun için kullanılacak adı ve kimliği olan bir Range olan NamedRange ekler: geri yükleyebilirsiniz.
getBody()BodySekmenin Body değerini alır.
getBookmark(id)BookmarkVerilen kimliğe sahip Bookmark öğesini alır.
getBookmarks()Bookmark[]Sekmedeki Bookmark nesnenin tümünü alır.
getFooter()FooterSectionSekmenin altbilgi bölümünü (varsa) alır.
getFootnotes()Footnote[]Sekmenin gövdesindeki tüm Footnote öğelerini alır.
getHeader()HeaderSectionVarsa sekmenin üstbilgi bölümünü alır.
getNamedRangeById(id)NamedRangeVerilen kimliğe sahip NamedRange öğesini alır.
getNamedRanges()NamedRange[]Sekmedeki NamedRange nesnenin tümünü alır.
getNamedRanges(name)NamedRange[]Belirtilen ada sahip sekmedeki NamedRange nesnenin tümünü alır.
newPosition(element, offset)PositionBir konuma göre sekmedeki bir konuma referans olan yeni bir Position oluşturur belirli bir öğedir.
newRange()RangeBuilderSekme öğelerinden Range nesneleri oluşturmak için kullanılan bir oluşturucu oluşturur.

Ayrıntılı belgeler

addBookmark(position)

Belirtilen Position için bir Bookmark ekler.

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

Parametreler

AdTürAçıklama
positionPositionYeni yer işaretinin konumu.

Return

Bookmark — Yeni yer işareti.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan bir veya daha fazlasıyla yetkilendirme gerektirir:

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

addFooter()

Yoksa sekme altbilgisi bölümü ekler.

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

Return

FooterSection: Sekme altbilgisi.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan bir veya daha fazlasıyla yetkilendirme gerektirir:

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

addHeader()

Yoksa, sekme üstbilgisi bölümü ekler.

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

Return

HeaderSection: Sekme başlığı.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan bir veya daha fazlasıyla yetkilendirme gerektirir:

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

addNamedRange(name, range)

Şunun için kullanılacak adı ve kimliği olan bir Range olan NamedRange ekler: geri yükleyebilirsiniz. Adların farklı sekmelerde bile benzersiz olması gerekmez; farklı zaman aralıklarında doküman, HTML'deki bir sınıf gibi aynı adı paylaşabilir. Buna karşın, kimlikler (HTML'deki bir kimlik gibi) belge içinde benzersizdir. NamedRange ekledikten sonra şu işlemi yapamazsınız: yalnızca siz kaldırabilirsiniz.

Sekmeye erişen tüm komut dosyaları bir NamedRange öğesine erişebilir. İstenmeyen değişikliklerden kaçınmak için komut dosyaları arasında çakışma varsa aralık adlarının önüne benzersiz bir dize ekleyebilirsiniz.

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

Parametreler

AdTürAçıklama
nameStringAralık adı (benzersiz olması gerekmez); aralık adları şöyle olmalıdır: 1-256 karakter arasında.
rangeRangeAdla ilişkilendirilecek öğe aralığı; aralık bir arama sonucu olabilir veya newRange() ile manuel olarak oluşturulabilir.

Return

NamedRangeNamedRange.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan bir veya daha fazlasıyla yetkilendirme gerektirir:

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

getBody()

Sekmenin Body değerini alır.

Sekmeler farklı türde bölümler içerebilir (örneğin, HeaderSection, FooterSection). Bir sekmenin etkin bölümü Body şeklindedir.

DocumentTab öğesindeki öğe yöntemleri, Body için yetki verir.

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

Return

Body — Sekmenin gövde bölümü.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan bir veya daha fazlasıyla yetkilendirme gerektirir:

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

getBookmark(id)

Verilen kimliğe sahip Bookmark öğesini alır. Sekme içinde böyle bir Bookmark yoksa bu yöntem null değerini döndürür.

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

Parametreler

AdTürAçıklama
idStringBookmark için kimlik.

Return

Bookmark — Verilen kimliğe sahip Bookmark veya böyle bir Bookmark yoksa null var.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan bir veya daha fazlasıyla yetkilendirme gerektirir:

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

getBookmarks()

Sekmedeki Bookmark nesnenin tümünü alır.

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

Return

Bookmark[] — Sekmedeki Bookmark nesnelerinden oluşan bir dizi.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan bir veya daha fazlasıyla yetkilendirme gerektirir:

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

getFooter()

Sekmenin altbilgi bölümünü (varsa) alır.

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

Return

FooterSection: Sekmenin alt bilgisi.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan bir veya daha fazlasıyla yetkilendirme gerektirir:

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

getFootnotes()

Sekmenin gövdesindeki tüm Footnote öğelerini alır.

getFootnotes için yapılan çağrılar, sekmenin öğeleri üzerinde iterasyona neden olur. Büyük sekmelerde bu yönteme yapılan gereksiz çağrılardan kaçının.

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

Return

Footnote[] — Sekmenin dipnotları.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan bir veya daha fazlasıyla yetkilendirme gerektirir:

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

getHeader()

Varsa sekmenin üstbilgi bölümünü alır.

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

Return

HeaderSection: Sekmenin başlığı.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan bir veya daha fazlasıyla yetkilendirme gerektirir:

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

getNamedRangeById(id)

Verilen kimliğe sahip NamedRange öğesini alır. Böyle bir değer yoksa bu yöntem null değerini döndürür Sekmede NamedRange mevcut. Adların, sekmeler arasında bile benzersiz olması gerekmez; aynı dokümandaki birkaç farklı aralık aynı adı paylaşabilir; tıpkı bir HTML'ye dokunun. Buna karşılık, kimlikler sekme içinde benzersizdir (HTML'deki bir kimlik gibi).

Parametreler

AdTürAçıklama
idStringSekme içinde benzersiz olan aralığın kimliği.

Return

NamedRange — Verilen kimliğe sahip NamedRange veyanull tıklayın.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan bir veya daha fazlasıyla yetkilendirme gerektirir:

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

getNamedRanges()

Sekmedeki NamedRange nesnenin tümünü alır.

NamedRange uygulamasına, sekmeye erişen herhangi bir komut dosyası tarafından erişilebilir. Kaçınılması gerekenler komut dosyaları arasında istenmeyen çakışmalar varsa aralık adlarının önüne benzersiz bir dize ekleyin.

Return

NamedRange[] — Sekmedeki NamedRange nesnelerinden oluşan bir dizi (büyük olasılıkla birden fazla öğe içerir) aynı ada sahip aralıklar.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan bir veya daha fazlasıyla yetkilendirme gerektirir:

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

getNamedRanges(name)

Belirtilen ada sahip sekmedeki NamedRange nesnenin tümünü alır. Adların (sekmeler arasında bile) aynı dokümandaki birkaç farklı aralık aynı adı, HTML'deki bir sınıfa çok benzer. Buna karşılık, kimlikler sekmenin içinde benzersizdir. HTML'ye dokunun.

NamedRange uygulamasına, sekmeye erişen herhangi bir komut dosyası tarafından erişilebilir. Kaçınılması gerekenler komut dosyaları arasında istenmeyen çakışmalar varsa aralık adlarının önüne benzersiz bir dize ekleyin.

Parametreler

AdTürAçıklama
nameStringHer zaman benzersiz olmayan aralığın adı.

Return

NamedRange[] — Belirtilen ada sahip sekmedeki NamedRange nesne dizisi.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan bir veya daha fazlasıyla yetkilendirme gerektirir:

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

newPosition(element, offset)

Bir konuma göre sekmedeki bir konuma referans olan yeni bir Position oluşturur belirli bir öğedir. Kullanıcının imleci, diğer kullanımların yanı sıra Position olarak gösterilir.

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

Parametreler

AdTürAçıklama
elementElementYeni oluşturulan Position öğesini içeren öğe; bu olmalıdır bir Text öğesi veya Paragraph gibi bir kapsayıcı öğe.
offsetIntegerText öğeleri için Position öğesinden önceki karakter sayısı; diğer öğeler için, Position aynı kapsayıcı öğedir.

Return

Position — Yeni Position.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan bir veya daha fazlasıyla yetkilendirme gerektirir:

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

newRange()

Sekme öğelerinden Range nesneleri oluşturmak için kullanılan bir oluşturucu oluşturur.

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

Return

RangeBuilder — Yeni oluşturucu.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan bir veya daha fazlasıyla yetkilendirme gerektirir:

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