כרטיסיית מסמך שמכילה טקסט עשיר ורכיבים כמו טבלאות ורשימות.
כדי לאחזר כרטיסייה של מסמך, משתמשים ב-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();
Methods
| שיטה | סוג הערך שמוחזר | תיאור קצר |
|---|---|---|
add | Bookmark | הפונקציה מוסיפה Bookmark ב-Position שצוין. |
add | Footer | מוסיף קטע של כותרת תחתונה לכרטיסייה, אם לא קיים כזה. |
add | Header | מוסיף קטע של כותרת לכרטיסייה, אם לא קיים כזה. |
add | Named | מוסיף Named, שהוא Range עם שם ומזהה לשימוש באחזור מאוחר יותר. |
get | Body | מאחזר את Body של הכרטיסייה. |
get | Bookmark|null | מקבל את Bookmark עם המזהה הנתון. |
get | Bookmark[] | מקבל את כל האובייקטים של Bookmark בכרטיסייה. |
get | Footer | מאחזר את קטע הכותרת התחתונה של הכרטיסייה, אם קיים. |
get | Footnote[]|null | הפונקציה מאחזרת את כל רכיבי Footnote בגוף הכרטיסייה. |
get | Header | מחזירה את קטע הכותרת של הכרטיסייה, אם קיים. |
get | Named | מקבל את Named עם המזהה הנתון. |
get | Named | מקבל את כל האובייקטים של Named בכרטיסייה. |
get | Named | מחזירה את כל האובייקטים מסוג Named בכרטיסייה עם השם שצוין. |
new | Position | יוצרת אובייקט Position חדש, שהוא הפניה למיקום בכרטיסייה, ביחס לרכיב ספציפי. |
new | Range | יוצרת כלי לבנייה שמשמש ליצירת אובייקטים מסוג Range מרכיבי כרטיסיות. |
תיעוד מפורט
add Bookmark(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
add Header()
מוסיף קטע של כותרת לכרטיסייה, אם לא קיים כזה.
// 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');
חזרה
Header — כותרת הכרטיסייה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
add Named Range(name, range)
מוסיף Named, שהוא Range עם שם ומזהה לשימוש באחזור מאוחר יותר. השמות לא בהכרח ייחודיים, גם לא בין כרטיסיות שונות. כמה טווחים שונים באותו מסמך יכולים לחלוק את אותו השם, בדומה למחלקה ב-HTML. לעומת זאת, מזהים הם ייחודיים במסמך, כמו מזהה ב-HTML. אחרי שמוסיפים Named אי אפשר לשנות אותו, אפשר רק להסיר אותו.
כל סקריפט שיש לו גישה לכרטיסייה יכול לגשת ל-Named. כדי למנוע התנגשויות לא מכוונות בין סקריפטים, מומלץ להוסיף מחרוזת ייחודית בתחילת שמות הטווחים.
// 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 | השם של הטווח, לא חייב להיות ייחודי. שמות הטווחים צריכים להיות באורך של 1 עד 256 תווים. |
range | Range | טווח הרכיבים שאליו משויך השם. הטווח יכול להיות תוצאת חיפוש או טווח שנבנה באופן ידני באמצעות new. |
חזרה
Named — The Named.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Body()
מאחזר את Body של הכרטיסייה.
כרטיסיות יכולות להכיל סוגים שונים של קטעים (לדוגמה, Header, Footer). הקטע הפעיל בכרטיסייה הוא Body.
השיטות של רכיב Document מוקצות ל-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 – קטע ה-body של הכרטיסייה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Bookmark(id)
מקבל את Bookmark עם המזהה הנתון. הפונקציה מחזירה null אם לא קיים 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 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 עם המזהה הנתון, או null אם לא קיים Bookmark כזה בכרטיסייה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Bookmarks()
מקבל את כל האובייקטים של 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
get Footnotes()
הפונקציה מאחזרת את כל רכיבי Footnote בגוף הכרטיסייה.
קריאות ל-get גורמות לאיטרציה על רכיבי הכרטיסייה. אם מדובר בכרטיסיות גדולות,
מומלץ להימנע מקריאות מיותרות לשיטה הזו.
// 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
get Header()
מחזירה את קטע הכותרת של הכרטיסייה, אם קיים.
// 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());
חזרה
Header — הכותרת של הכרטיסייה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Named Range By Id(id)
מקבל את Named עם המזהה הנתון. השיטה הזו מחזירה null אם לא קיים Named בכרטיסייה. השמות לא בהכרח ייחודיים, גם לא בין כרטיסיות שונות. יכול להיות שלכמה טווחי תאים שונים באותו מסמך יהיה אותו שם, בדומה למחלקה ב-HTML. לעומת זאת, מזהים הם ייחודיים בתוך הכרטיסייה, כמו מזהה ב-HTML.
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
id | String | המזהה של הטווח, שהוא ייחודי בגיליון. |
חזרה
Named – ה-Named עם המזהה שצוין, או null אם לא קיים טווח כזה בכרטיסייה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Named Ranges()
מקבל את כל האובייקטים של Named בכרטיסייה.
כל סקריפט שיש לו גישה לכרטיסייה יכול לגשת ל-Named. כדי למנוע קונפליקטים לא מכוונים בין סקריפטים, כדאי להוסיף מחרוזת ייחודית בתחילת השמות של טווחי התאים.
חזרה
Named – מערך של אובייקטים מסוג Named בכרטיסייה, שיכול לכלול כמה טווחים עם אותו שם.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Named Ranges(name)
מחזירה את כל האובייקטים מסוג Named בכרטיסייה עם השם שצוין. השמות לא בהכרח ייחודיים, גם לא בין כרטיסיות שונות. יכול להיות שלכמה טווחי תאים שונים באותו מסמך יהיה אותו שם, בדומה למחלקה ב-HTML. לעומת זאת, מזהים הם ייחודיים בתוך הכרטיסייה, כמו מזהה ב-HTML.
כל סקריפט שיש לו גישה לכרטיסייה יכול לגשת ל-Named. כדי למנוע קונפליקטים לא מכוונים בין סקריפטים, כדאי להוסיף מחרוזת ייחודית בתחילת השמות של טווחי התאים.
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
name | String | השם של הטווח, שלא חייב להיות ייחודי. |
חזרה
Named – מערך של אובייקטים מסוג Named בכרטיסייה עם השם שצוין.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
new Position(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
new Range()
יוצרת כלי לבנייה שמשמש ליצירת אובייקטים מסוג Range מרכיבי כרטיסיות.
// 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());
חזרה
Range – הכלי החדש ליצירת קהלים.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents