یک برگه سند، حاوی متن غنی و عناصری مانند جداول و لیستها.
با استفاده از Document.getTabs()[tabIndex].asDocumentTab() یک تب سند را بازیابی کنید.
// 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();
روشها
| روش | نوع بازگشتی | شرح مختصر |
|---|---|---|
add Bookmark(position) | Bookmark | یک Bookmark در Position داده شده اضافه میکند. |
add Footer() | Footer Section | اگر بخشی در پاورقی برگه وجود نداشته باشد، آن را اضافه میکند. |
add Header() | Header Section | اگر بخشی برای سربرگ تب وجود نداشته باشد، آن را اضافه میکند. |
add Named Range(name, range) | Named Range | یک Named Range اضافه میکند، که Range است که دارای نام و شناسه برای استفاده در بازیابیهای بعدی است. |
get Body() | Body | Body تب را بازیابی میکند. |
get Bookmark(id) | Bookmark |null | Bookmark با شناسهی داده شده دریافت میکند. |
get Bookmarks() | Bookmark[] | تمام اشیاء Bookmark در تب را دریافت میکند. |
get Footer() | Footer Section |null | در صورت وجود، بخش پاورقی برگه را بازیابی میکند. |
get Footnotes() | Footnote[] |null | تمام عناصر Footnote را در بدنه تب بازیابی میکند. |
get Header() | Header Section |null | در صورت وجود، بخش سربرگ تب را بازیابی میکند. |
get Named Range By Id(id) | Named Range |null | Named Range با شناسهی داده شده را دریافت میکند. |
get Named Ranges() | Named Range[] | تمام اشیاء Named Range را در برگه دریافت میکند. |
get Named Ranges(name) | Named Range[] | تمام اشیاء Named Range را در تب با نام داده شده دریافت میکند. |
new Position(element, offset) | Position | یک Position جدید ایجاد میکند که ارجاعی به مکانی در تب، نسبت به یک عنصر خاص است. |
new Range() | Range Builder | یک سازنده ایجاد میکند که برای ساخت اشیاء Range از عناصر tab استفاده میشود. |
مستندات دقیق
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('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());
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
position | Position | موقعیت نشانک جدید. |
بازگشت
Bookmark — نشانک جدید.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
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('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');
بازگشت
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. 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());
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
name | String | نام محدوده، که نیازی به منحصر به فرد بودن ندارد؛ نام محدوده باید بین ۱ تا ۲۵۶ کاراکتر باشد. |
range | Range | محدوده عناصری که باید به نام مرتبط شوند؛ این محدوده میتواند نتیجه جستجو باشد یا به صورت دستی با new Range() ساخته شود. |
بازگشت
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('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());
بازگشت
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('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.'); }
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
id | String | شناسهی Bookmark . |
بازگشت
Bookmark |null — 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('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);
بازگشت
Bookmark[] — آرایهای از اشیاء Bookmark در تب.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
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('123abc').getTab('123abc').asDocumentTab(); // Gets the first footnote. const footnote = documentTab.getFootnotes()[0]; // Logs footnote contents to the console. console.log(footnote.getFootnoteContents().getText());
بازگشت
Footnote[] |null — پاورقیهای تب.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
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('123abc').getTab('123abc').asDocumentTab(); // Gets the text of the tab's header and logs it to the console. console.log(documentTab.getHeader().getText());
بازگشت
HeaderSection |null — سربرگ برگه.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getNamedRangeById(id)
NamedRange با شناسه داده شده دریافت میکند. اگر چنین NamedRange در برگه وجود نداشته باشد، این متد null را برمیگرداند. نامها لزوماً منحصر به فرد نیستند، حتی در بین برگهها؛ چندین محدوده مختلف در یک سند ممکن است نام یکسانی داشته باشند، دقیقاً مانند یک کلاس در HTML. در مقابل، شناسهها در داخل برگه منحصر به فرد هستند، مانند یک شناسه در HTML.
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
id | String | شناسهی محدوده، که در هر برگه منحصر به فرد است. |
بازگشت
NamedRange |null — 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. 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);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
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 از عناصر tab استفاده میشود.
// 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());
بازگشت
RangeBuilder — سازنده جدید.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents