Class DocumentTab

BelgeSekmesi

Zengin metin ve tablo, liste gibi öğeler içeren bir doküman sekmesi.

Document.getTabs()[tabIndex].asDocumentTab() kullanarak bir doküman sekmesini geri getirme

// Get a specific document tab based on the tab ID.
// TODO(developer): Replace the IDs with your own.
const documentTab =
    DocumentApp.openById('123abc').getTab('123abc').asDocumentTab();

Yöntemler

YöntemDönüş türüKısa açıklama
addBookmark(position)BookmarkBelirtilen Position konumuna Bookmark ekler.
addFooter()FooterSectionYoksa sekme altbilgi bölümü ekler.
addHeader()HeaderSectionSekme üstbilgisi bölümü yoksa ekler.
addNamedRange(name, range)NamedRangeDaha sonra almak için adı ve kimliği olan bir Range olan NamedRange ekler.
getBody()BodySekmenin Body değerini alır.
getBookmark(id)Bookmark|nullBelirtilen kimliğe sahip Bookmark öğesini alır.
getBookmarks()Bookmark[]Sekmedeki tüm Bookmark nesnelerini alır.
getFooter()FooterSection|nullVarsa sekmenin altbilgi bölümünü alır.
getFootnotes()Footnote[]|nullSekmenin gövdesindeki tüm Footnote öğelerini alır.
getHeader()HeaderSection|nullVarsa sekmenin başlık bölümünü alır.
getNamedRangeById(id)NamedRange|nullBelirtilen kimliğe sahip NamedRange öğesini alır.
getNamedRanges()NamedRange[]Sekmedeki tüm NamedRange nesnelerini alır.
getNamedRanges(name)NamedRange[]Belirtilen ada sahip sekmedeki tüm NamedRange nesnelerini alır.
newPosition(element, offset)PositionSekmedeki bir konuma referans veren yeni bir Position oluşturur. Bu konum, belirli bir öğeye göre belirlenir.
newRange()RangeBuilderSekme öğelerinden Range nesneleri oluşturmak için kullanılan bir oluşturucu oluşturur.

Ayrıntılı belgeler

addBookmark(position)

Belirtilen Position konumuna Bookmark ekler.

// Opens the Docs file and retrieves the tab by its IDs. If you created your
// script from within a Google Docs file, you can use
// DocumentApp.getActiveDocument().getActiveTab() instead.
// TODO(developer): Replace the IDs with your own.
const documentTab =
    DocumentApp.openById('123abc').getTab('123abc').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 biri veya daha fazlasıyla yetkilendirme gerektirir:

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

addFooter()

Yoksa sekme altbilgi bölümü ekler.

// Opens the Docs file and retrieves the tab by its IDs. If you created your
// script from within a Google Docs file, you can use
// DocumentApp.getActiveDocument().getActiveTab() instead.
// TODO(developer): Replace the IDs with your own.
const documentTab =
    DocumentApp.openById('123abc').getTab('123abc').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 biri veya daha fazlasıyla yetkilendirme gerektirir:

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

addHeader()

Sekme üstbilgisi bölümü yoksa ekler.

// Opens the Docs file and retrieves the tab by its IDs. If you created your
// script from within a Google Docs file, you can use
// DocumentApp.getActiveDocument().getActiveTab() instead.
// TODO(developer): Replace the IDs with your own.
const documentTab =
    DocumentApp.openById('123abc').getTab('123abc').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 biri veya daha fazlasıyla yetkilendirme gerektirir:

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

addNamedRange(name, range)

Daha sonra almak için adı ve kimliği olan bir Range olan NamedRange ekler. Adlar, sekmeler arasında bile benzersiz olmayabilir. Aynı belgedeki birkaç farklı aralık, HTML'deki bir sınıf gibi aynı adı paylaşabilir. Buna karşılık, kimlikler HTML'deki bir kimlik gibi doküman içinde benzersizdir. Eklediğiniz bir NamedRange değiştirilemez, yalnızca kaldırılabilir.

Sekmeye erişen tüm komut dosyaları NamedRange değerine erişebilir. Komut dosyaları arasında istenmeyen çakışmaları önlemek için aralık adlarına benzersiz bir dizeyle önek eklemeyi düşünebilirsiniz.

// Creates a named range that includes every table in a tab by its ID.
// TODO(developer): Replace the IDs with your own.
const documentTab =
    DocumentApp.openById('123abc').getTab('123abc').asDocumentTab();
const rangeBuilder = documentTab.newRange();
const tables = documentTab.getBody().getTables();
for (let i = 0; i < tables.length; i++) {
  rangeBuilder.addElement(tables[i]);
}
documentTab.addNamedRange('Tab t.0 tables', rangeBuilder.build());

Parametreler

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

Return

NamedRangeNamedRange.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan biri 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ürlerde bölümler (ör. HeaderSection, FooterSection) içerebilir. Bir sekmenin etkin bölümü Body'dir.

DocumentTab içindeki öğe yöntemleri Body öğesine temsilci olarak atanır.

// Opens the Docs file and retrieves the tab by its IDs. If you created your
// script from within a Google Docs file, you can use
// DocumentApp.getActiveDocument().getActiveTab() instead.
// TODO(developer): Replace the IDs with your own.
const documentTab =
    DocumentApp.openById('123abc').getTab('123abc').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 biri veya daha fazlasıyla yetkilendirme gerektirir:

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

getBookmark(id)

Belirtilen kimliğe sahip Bookmark öğesini alır. Bu sekmede böyle bir Bookmark yoksa bu yöntem null değerini döndürür.

// Opens the Docs file and retrieves the tab by its IDs. If you created your
// script from within a Google Docs file, you can use
// DocumentApp.getActiveDocument().getActiveTab() instead.
// TODO(developer): Replace the IDs with your own.
const documentTab =
    DocumentApp.openById('123abc').getTab('123abc').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|null: Belirtilen kimliğe sahip Bookmark veya sekmede böyle bir Bookmark yoksa null.

Yetkilendirme

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

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

getBookmarks()

Sekmedeki tüm Bookmark nesnelerini alır.

// Opens the Docs file and retrieves the tab by its IDs. If you created your
// script from within a Google Docs file, you can use
// DocumentApp.getActiveDocument().getActiveTab() instead.
// TODO(developer): Replace the IDs with your own.
const documentTab =
    DocumentApp.openById('123abc').getTab('123abc').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 nesnelerinin dizisi.

Yetkilendirme

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

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

getFooter()

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

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

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

Return

FooterSection|null: Sekmenin altbilgisi.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan biri 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 çağrıları, sekmenin öğeleri üzerinde yinelemeye neden olur. Büyük sekmeler için bu yönteme gereksiz çağrılardan kaçının.

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

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

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

Return

Footnote[]|null: Sekmenin dipnotları.

Yetkilendirme

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

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

getHeader()

Varsa sekmenin başlık bölümünü alır.

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

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

Return

HeaderSection|null: Sekmenin başlığı.

Yetkilendirme

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

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

getNamedRangeById(id)

Belirtilen kimliğe sahip NamedRange öğesini alır. Bu yöntem, sekmede böyle bir null yoksa NamedRange değerini döndürür. Adlar, sekmeler arasında bile benzersiz olmayabilir. Aynı dokümandaki birkaç farklı aralık, HTML'deki bir sınıf gibi aynı adı paylaşabilir. Buna karşılık, kimlikler HTML'deki bir kimlik gibi sekme içinde benzersizdir.

Parametreler

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

Return

NamedRange|null: Belirtilen kimliğe sahip NamedRange veya sekmede böyle bir aralık yoksa null.

Yetkilendirme

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

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

getNamedRanges()

Sekmedeki tüm NamedRange nesnelerini alır.

Bir NamedRange, sekmeye erişen tüm komut dosyaları tarafından kullanılabilir. Komut dosyaları arasında istenmeyen çakışmaları önlemek için aralık adlarının önüne benzersiz bir dize ekleyebilirsiniz.

Return

NamedRange[]: Sekmedeki NamedRange nesnelerinin dizisi. Aynı ada sahip birden fazla aralık içerebilir.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan biri 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 tüm NamedRange nesnelerini alır. Adlar, sekmeler arasında bile benzersiz olmak zorunda değildir. Aynı dokümandaki birkaç farklı aralık, HTML'deki bir sınıf gibi aynı adı paylaşabilir. Buna karşılık, kimlikler sekme içinde benzersizdir (ör. HTML'deki bir kimlik).

Bir NamedRange, sekmeye erişen tüm komut dosyaları tarafından kullanılabilir. Komut dosyaları arasında istenmeyen çakışmaları önlemek için aralık adlarının önüne benzersiz bir dize ekleyebilirsiniz.

Parametreler

AdTürAçıklama
nameStringAralığın adı (benzersiz olması gerekmez).

Return

NamedRange[]: Belirtilen ada sahip sekmedeki NamedRange nesnelerinin dizisi.

Yetkilendirme

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

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

newPosition(element, offset)

Sekmedeki bir konuma referans veren yeni bir Position oluşturur. Bu konum, belirli bir öğeye göre belirlenir. 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.
// TODO(developer): Replace the IDs with your own.
const doc = DocumentApp.openById('123abc');
const documentTab = doc.getTab('123abc').asDocumentTab();
const paragraph = documentTab.getBody().appendParagraph('My new paragraph.');
const position = documentTab.newPosition(paragraph.getChild(0), 2);
doc.setCursor(position);

Parametreler

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

Return

Position — Yeni Position.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamlardan biri 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.
// TODO(developer): Replace the IDs with your own.
const doc = DocumentApp.openById('123abc');
const documentTab = doc.getTab('123abc').asDocumentTab();
const rangeBuilder = documentTab.newRange();
const tables = documentTab.getBody().getTables();
for (let 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 biri veya daha fazlasıyla yetkilendirme gerektirir:

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