Class DocumentTab

DocumentTab

یک برگه سند، حاوی متن غنی و عناصری مانند جداول و لیست ها.

یک برگه سند را با استفاده از Document.getTabs()[tabIndex].asDocumentTab() بازیابی کنید.

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

روش ها

روش نوع برگشت شرح مختصر
addBookmark(position) Bookmark یک Bookmark در Position داده شده اضافه می کند.
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)

یک Bookmark در Position داده شده اضافه می کند.

// 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(DOCUMENT_ID).getTab(TAB_ID).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());

پارامترها

نام تایپ کنید توضیحات
position Position موقعیت نشانک جدید.

بازگشت

Bookmark - نشانک جدید.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

addFooter()

یک بخش پاورقی برگه را اضافه می کند، اگر وجود نداشته باشد.

// 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(DOCUMENT_ID).getTab(TAB_ID).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 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(DOCUMENT_ID).getTab(TAB_ID).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. در مقابل، شناسه‌ها در سند منحصر به فرد هستند، مانند شناسه در HTML. بعد از اینکه یک NamedRange اضافه کردید، نمی توانید آن را تغییر دهید، فقط می توانید آن را حذف کنید.

هر اسکریپتی که به برگه دسترسی داشته باشد می تواند به NamedRange دسترسی داشته باشد. برای جلوگیری از درگیری های ناخواسته بین اسکریپت ها، پیشوند نام محدوده را با یک رشته منحصر به فرد در نظر بگیرید.

// Creates a named range that includes every table in a tab by its ID.
// TODO(developer): Replace the IDs with your own.
var documentTab = DocumentApp.openById(DOCUMENT_ID).getTab(TAB_ID).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());

پارامترها

نام تایپ کنید توضیحات
name String نام محدوده، که لازم نیست منحصر به فرد باشد. نام محدوده باید بین 1 تا 256 کاراکتر باشد.
range Range محدوده عناصری که باید با نام مرتبط شوند. محدوده می تواند یک نتیجه جستجو باشد یا به صورت دستی با newRange() ساخته شود.

بازگشت

NamedRange - NamedRange .

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getBody()

Body برگه را بازیابی می کند.

برگه ها ممکن است شامل انواع مختلفی از بخش ها باشند (به عنوان مثال، HeaderSection ، FooterSection ). بخش فعال یک برگه Body است.

روش های عنصر در DocumentTab به Body تفویض می شود.

// 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(DOCUMENT_ID).getTab(TAB_ID).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 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(DOCUMENT_ID).getTab(TAB_ID).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.');
}

پارامترها

نام تایپ کنید توضیحات
id String شناسه Bookmark .

بازگشت

Bookmark - Bookmark با شناسه داده شده، یا اگر چنین Bookmark در برگه وجود نداشته باشد null .

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getBookmarks()

همه اشیاء Bookmark را در برگه دریافت می کند.

// 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(DOCUMENT_ID).getTab(TAB_ID).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 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(DOCUMENT_ID).getTab(TAB_ID).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 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(DOCUMENT_ID).getTab(TAB_ID).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 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(DOCUMENT_ID).getTab(TAB_ID).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 با شناسه داده شده دریافت می کند. اگر چنین NamedRange در برگه وجود نداشته باشد، این متد null را برمی‌گرداند. نام‌ها لزوماً منحصر به فرد نیستند، حتی در سربرگ‌ها. چندین محدوده مختلف در یک سند ممکن است نام یکسانی داشته باشند، بسیار شبیه یک کلاس در HTML. در مقابل، شناسه‌ها مانند شناسه در HTML منحصربه‌فرد هستند.

پارامترها

نام تایپ کنید توضیحات
id String شناسه محدوده، که در برگه منحصر به فرد است.

بازگشت

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. در مقابل، شناسه‌ها مانند شناسه در HTML منحصربه‌فرد هستند.

یک NamedRange با هر اسکریپتی که به برگه دسترسی دارد قابل دسترسی است. برای جلوگیری از درگیری های ناخواسته بین اسکریپت ها، پیشوند نام محدوده را با یک رشته منحصر به فرد در نظر بگیرید.

پارامترها

نام تایپ کنید توضیحات
name String نام محدوده، که لزوما منحصر به فرد نیست.

بازگشت

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.
// TODO(developer): Replace the IDs with your own.
var doc = DocumentApp.openById(DOCUMENT_ID);
var documentTab = doc.getTab(TAB_ID).asDocumentTab();
var paragraph = documentTab.getBody().appendParagraph('My new paragraph.');
var position = documentTab.newPosition(paragraph.getChild(0), 2);
doc.setCursor(position);

پارامترها

نام تایپ کنید توضیحات
element Element عنصری که حاوی Position جدید ایجاد شده به; این باید یا یک عنصر Text یا یک عنصر ظرف مانند Paragraph باشد.
offset Integer برای عناصر Text ، تعداد کاراکترهای قبل از 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.
// TODO(developer): Replace the IDs with your own.
var doc = DocumentApp.openById(DOCUMENT_ID);
var documentTab = doc.getTab(TAB_ID).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