רכיב שמייצג טבלה. רכיב Table יכול להכיל רק רכיבי TableRow. מידע נוסף על מבנה המסמך זמין במדריך להרחבת Google Docs.
כשיוצרים Table שמכיל מספר גדול של שורות או תאים, כדאי לבנות אותו ממערך מחרוזות, כמו בדוגמה הבאה.
const body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody(); // Create a two-dimensional array containing the cell contents. const cells = [ ['Row 1, Cell 1', 'Row 1, Cell 2'], ['Row 2, Cell 1', 'Row 2, Cell 2'], ]; // Build a table from the array. body.appendTable(cells);
Methods
| שיטה | סוג הערך שמוחזר | תיאור קצר |
|---|---|---|
append | Table | יוצרת Table חדש ומצרפת אותו. |
append | Table | הוספה של Table. |
clear() | Table | מחיקת התוכן של הרכיב. |
copy() | Table | הפונקציה מחזירה עותק מנותק ועמוק של הרכיב הנוכחי. |
edit | Text | מקבלים גרסה Text של הרכיב הנוכחי לצורך עריכה. |
find | Range | מחפש בתוכן של הרכיב צאצא מסוג מסוים. |
find | Range | הפונקציה מחפשת בתוכן של הרכיב צאצא מסוג מסוים, החל מRange שצוין. |
find | Range | מחפשת בתוכן של הרכיב את תבנית הטקסט שצוינה באמצעות ביטויים רגולריים. |
find | Range | מחפש בתוכן של הרכיב את תבנית הטקסט שצוינה, החל מתוצאת חיפוש נתונה. |
get | Object | מאחזר את המאפיינים של האלמנט. |
get | String|null | מאחזר את צבע הגבול. |
get | Number|null | מאחזרת את רוחב הגבול, בנקודות. |
get | Table | אחזור הערך Table באינדקסים של השורה והתא שצוינו. |
get | Element | מאחזר את רכיב הצאצא באינדקס הצאצא שצוין. |
get | Integer | מאחזר את אינדקס הצאצא של רכיב הצאצא שצוין. |
get | Number|null | הפונקציה מאחזרת את הרוחב של עמודה מסוימת בטבלה, בנקודות. |
get | String|null | הפונקציה מחזירה את כתובת ה-URL של הקישור. |
get | Element|null | מאחזר את רכיב האח הבא של הרכיב. |
get | Integer | מאחזר את מספר הילדים. |
get | Integer | הפונקציה מאחזרת את מספר Table. |
get | Container | מאחזר את רכיב ההורה של הרכיב. |
get | Element|null | אחזור של רכיב האחות הקודם של הרכיב. |
get | Table | מאחזרת את Table באינדקס השורה שצוין. |
get | String | מאחזרת את התוכן של הרכיב כמחרוזת טקסט. |
get | Text | מחזירה את יישור הטקסט. |
get | Element | אחזור Element של הרכיב. |
insert | Table | יוצרת ומכניסה אובייקט Table חדש באינדקס שצוין. |
insert | Table | הפונקציה מוסיפה את Table שצוין באינדקס שצוין. |
is | Boolean | קובע אם הרכיב נמצא בסוף Document. |
remove | Table | הסרת רכיב הבן שצוין. |
remove | Table|null | הפונקציה מסירה את הרכיב מהרכיב ההורה שלו. |
remove | Table | מסירה את Table באינדקס השורה שצוין. |
replace | Element | הפונקציה מחליפה את כל המופעים של תבנית טקסט נתונה במחרוזת חלופית נתונה, באמצעות ביטויים רגולריים. |
set | Table | הגדרת המאפיינים של האלמנט. |
set | Table | הגדרת צבע הגבול. |
set | Table | מגדיר את רוחב הגבול, בנקודות. |
set | Table | מגדירה את הרוחב של העמודה שצוינה, בנקודות. |
set | Table | מגדיר את כתובת ה-URL של הקישור. |
set | Table | הגדרת יישור הטקסט. |
תיעוד מפורט
appendTableRow()
appendTableRow(tableRow)
הוספה של TableRow.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the first table in the tab and copies the second row. const table = body.getTables()[0]; const row = table.getChild(1).copy(); // Adds the copied row to the bottom of the table. const tableRow = table.appendTableRow(row);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
table | Table | השורה בטבלה שרוצים לצרף. |
חזרה
TableRow — רכיב השורה בטבלה שנוספה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
clear()
copy()
הפונקציה מחזירה עותק מנותק ועמוק של הרכיב הנוכחי.
כל רכיבי הצאצא שקיימים ברכיב מועתקים גם הם. לרכיב החדש אין רכיב אב.
חזרה
Table — העותק החדש.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
editAsText()
מקבלים גרסה Text של הרכיב הנוכחי לצורך עריכה.
אפשר להשתמש ב-editAsText כדי לשנות את תוכן הרכיבים כטקסט עשיר. במצב editAsText המערכת מתעלמת מאלמנטים שאינם טקסט (כמו InlineImage ו-HorizontalRule).
רכיבי צאצא שכלולים באופן מלא בטווח טקסט שנמחק מוסרים מהרכיב.
const body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody(); // Insert two paragraphs separated by a paragraph containing an // horizontal rule. body.insertParagraph(0, 'An editAsText sample.'); body.insertHorizontalRule(0); body.insertParagraph(0, 'An example.'); // Delete " sample.\n\n An" removing the horizontal rule in the process. body.editAsText().deleteText(14, 25);
חזרה
Text — גרסת טקסט של הרכיב הנוכחי
findElement(elementType)
מחפש בתוכן של הרכיב צאצא מסוג מסוים.
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
element | Element | סוג הרכיב לחיפוש. |
חזרה
RangeElement|null — תוצאת חיפוש שמציינת את המיקום של רכיב החיפוש.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
findElement(elementType, from)
הפונקציה מחפשת בתוכן של הרכיב צאצא מסוג מסוים, החל מRangeElement שצוין.
const body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody(); // Define the search parameters. let searchResult = null; // Search until the paragraph is found. while ( (searchResult = body.findElement( DocumentApp.ElementType.PARAGRAPH, searchResult, ))) { const par = searchResult.getElement().asParagraph(); if (par.getHeading() === DocumentApp.ParagraphHeading.HEADING1) { // Found one, update and stop. par.setText('This is the first header.'); break; } }
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
element | Element | סוג הרכיב לחיפוש. |
from | Range | תוצאת החיפוש שממנה מתחילים את החיפוש. |
חזרה
RangeElement|null — תוצאת חיפוש שמציינת את המיקום הבא של רכיב החיפוש.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
findText(searchPattern)
מחפשת בתוכן של הרכיב את תבנית הטקסט שצוינה באמצעות ביטויים רגולריים.
קבוצת משנה של תכונות הביטוי הרגולרי של JavaScript לא נתמכות באופן מלא, כמו קבוצות לכידה ומשני מצב.
תבנית הביטוי הרגולרי שצוינה מושווית באופן עצמאי לכל בלוק טקסט שנכלל ברכיב הנוכחי.
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
search | String | התבנית לחיפוש |
חזרה
RangeElement|null – תוצאת חיפוש שמציינת את המיקום של טקסט החיפוש, או null אם אין התאמה
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
findText(searchPattern, from)
מחפש בתוכן של הרכיב את תבנית הטקסט שצוינה, החל מתוצאת חיפוש נתונה.
קבוצת משנה של תכונות הביטוי הרגולרי של JavaScript לא נתמכות באופן מלא, כמו קבוצות לכידה ומשני מצב.
תבנית הביטוי הרגולרי שצוינה מושווית באופן עצמאי לכל בלוק טקסט שנכלל ברכיב הנוכחי.
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
search | String | התבנית לחיפוש |
from | Range | תוצאת החיפוש שממנה רוצים לחפש |
חזרה
RangeElement|null — תוצאת חיפוש שמציינת את המיקום הבא של טקסט החיפוש, או null אם אין התאמה
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getAttributes()
מאחזר את המאפיינים של האלמנט.
התוצאה היא אובייקט שמכיל מאפיין לכל מאפיין של רכיב תקין, כאשר כל שם מאפיין תואם לפריט בספירה DocumentApp.Attribute.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Append a styled paragraph. const par = body.appendParagraph('A bold, italicized paragraph.'); par.setBold(true); par.setItalic(true); // Retrieve the paragraph's attributes. const atts = par.getAttributes(); // Log the paragraph attributes. for (const att in atts) { Logger.log(`${att}:${atts[att]}`); }
חזרה
Object – מאפייני הרכיב.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getBorderColor()
מאחזר את צבע הגבול.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the first table. const table = body.getTables()[0]; // Sets the border color of the first table. table.setBorderColor('#00FF00'); // Logs the border color of the first table to the console. console.log(table.getBorderColor());
חזרה
String|null – צבע הגבול, בפורמט של סימון CSS (למשל '#ffffff').
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getBorderWidth()
מאחזרת את רוחב הגבול, בנקודות.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the first table. const table = body.getTables()[0]; // Sets the border width of the first table. table.setBorderWidth(20); // Logs the border width of the first table. console.log(table.getBorderWidth());
חזרה
Number|null — רוחב הגבול, בנקודות.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getCell(rowIndex, cellIndex)
אחזור הערך TableCell באינדקסים של השורה והתא שצוינו.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the first table. const table = body.getTables()[0]; // Gets the cell of the table's third row and second column. const cell = table.getCell(2, 1); // Logs the cell text to the console. console.log(cell.getText());
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
row | Integer | האינדקס של השורה שמכילה את התא שאותו רוצים לאחזר. |
cell | Integer | האינדקס של התא לאחזור. |
חזרה
TableCell|null — התא בטבלה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getChild(childIndex)
מאחזר את רכיב הצאצא באינדקס הצאצא שצוין.
const body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody(); // Obtain the first element in the tab. const firstChild = body.getChild(0); // If it's a paragraph, set its contents. if (firstChild.getType() === DocumentApp.ElementType.PARAGRAPH) { firstChild.asParagraph().setText('This is the first paragraph.'); }
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
child | Integer | האינדקס של רכיב הצאצא לאחזור. |
חזרה
Element – רכיב הצאצא באינדקס שצוין.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getChildIndex(child)
מאחזר את אינדקס הצאצא של רכיב הצאצא שצוין.
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
child | Element | רכיב הצאצא שעבורו רוצים לאחזר את האינדקס. |
חזרה
Integer — אינדקס הילד.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getColumnWidth(columnIndex)
הפונקציה מאחזרת את הרוחב של עמודה מסוימת בטבלה, בנקודות.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the first table. const table = body.getTables()[0]; // Sets the width of the second column to 100 points. const columnWidth = table.setColumnWidth(1, 100); // Gets the width of the second column and logs it to the console. console.log(columnWidth.getColumnWidth(1));
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
column | Integer | אינדקס העמודות. |
חזרה
Number|null – רוחב העמודה, בנקודות.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getLinkUrl()
הפונקציה מחזירה את כתובת ה-URL של הקישור.
חזרה
String|null – כתובת ה-URL של הקישור, או null אם הרכיב מכיל כמה ערכים למאפיין הזה
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getNextSibling()
מאחזר את רכיב האח הבא של הרכיב.
לרכיב הבא באותה רמה יש את אותו רכיב אב והוא מופיע אחרי הרכיב הנוכחי.
חזרה
Element|null – רכיב האחים הבא.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getNumChildren()
מאחזר את מספר הילדים.
const body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody(); // Log the number of elements in the tab. Logger.log(`There are ${body.getNumChildren()} elements in the tab's body.`);
חזרה
Integer — מספר הילדים.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getNumRows()
הפונקציה מאחזרת את מספר TableRows.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the first table. const table = body.getTables()[0]; // Logs the number of rows of the first table to the console. console.log(table.getNumRows());
חזרה
Integer — מספר השורות בטבלה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getParent()
מאחזר את רכיב ההורה של הרכיב.
רכיב ההורה מכיל את הרכיב הנוכחי.
חזרה
ContainerElement|null – רכיב ההורה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getPreviousSibling()
אחזור של רכיב האחות הקודם של הרכיב.
לאח או לאחות הקודמים יש את אותו רכיב אב והם קודמים לרכיב הנוכחי.
חזרה
Element|null – רכיב האח הקודם.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getRow(rowIndex)
מאחזרת את TableRow באינדקס השורה שצוין.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the first table and logs the text of first row to the console. const table = body.getTables()[0]; console.log(table.getRow(0).getText());
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
row | Integer | האינדקס של השורה לאחזור. |
חזרה
TableRow|null — השורה בטבלה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getText()
מאחזרת את התוכן של הרכיב כמחרוזת טקסט.
חזרה
String – התוכן של הרכיב כמחרוזת טקסט
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getTextAlignment()
מחזירה את יישור הטקסט. סוגי היישור הזמינים הם DocumentApp.TextAlignment.NORMAL, DocumentApp.TextAlignment.SUBSCRIPT ו-DocumentApp.TextAlignment.SUPERSCRIPT.
חזרה
TextAlignment|null – סוג יישור הטקסט, או null אם הטקסט מכיל כמה סוגים של יישור טקסט או אם יישור הטקסט לא הוגדר אף פעם
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getType()
אחזור ElementType של הרכיב.
משתמשים ב-getType() כדי לקבוע את הסוג המדויק של רכיב נתון.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Obtain the first element in the active tab's body. const firstChild = body.getChild(0); // Use getType() to determine the element's type. if (firstChild.getType() === DocumentApp.ElementType.PARAGRAPH) { Logger.log('The first element is a paragraph.'); } else { Logger.log('The first element is not a paragraph.'); }
חזרה
ElementType – סוג הרכיב.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
insertTableRow(childIndex)
יוצרת ומכניסה אובייקט TableRow חדש באינדקס שצוין.
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
child | Integer | האינדקס שבו יתווסף הרכיב |
חזרה
TableRow – הרכיב הנוכחי
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
insertTableRow(childIndex, tableRow)
הפונקציה מוסיפה את TableRow שצוין באינדקס שצוין.
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
child | Integer | האינדקס שבו יתווסף הרכיב |
table | Table | שורת הטבלה להוספה |
חזרה
TableRow – רכיב שורת הטבלה שהוכנס
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
isAtDocumentEnd()
removeChild(child)
הסרת רכיב הבן שצוין.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the first table. const table = body.getTables()[0]; // Finds the first table row and removes it. const element = table.findElement(DocumentApp.ElementType.TABLE_ROW); table.removeChild(element.getElement());
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
child | Element | רכיב הילד שרוצים להסיר. |
חזרה
Table – הרכיב הנוכחי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
removeFromParent()
הפונקציה מסירה את הרכיב מהרכיב ההורה שלו.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Remove all images in the active tab's body. const imgs = body.getImages(); for (let i = 0; i < imgs.length; i++) { imgs[i].removeFromParent(); }
חזרה
Table|null — הרכיב שהוסר.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
removeRow(rowIndex)
מסירה את TableRow באינדקס השורה שצוין.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the first table and removes its second row. const table = body.getTables()[0]; table.removeRow(1);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
row | Integer | האינדקס של השורה שרוצים להסיר. |
חזרה
TableRow – השורה שהוסרה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
replaceText(searchPattern, replacement)
הפונקציה מחליפה את כל המופעים של תבנית טקסט נתונה במחרוזת חלופית נתונה, באמצעות ביטויים רגולריים.
תבנית החיפוש מועברת כמחרוזת, ולא כאובייקט של ביטוי רגולרי ב-JavaScript. לכן, צריך לסמן בתו בריחה (escape) כל לוכסן הפוך בתבנית.
השיטה הזו משתמשת בספריית הביטויים הרגולריים RE2 של Google, שמגבילה את התחביר הנתמך.
תבנית הביטוי הרגולרי שצוינה מושווית באופן עצמאי לכל בלוק טקסט שנכלל ברכיב הנוכחי.
const body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody(); // Clear the text surrounding "Apps Script", with or without text. body.replaceText('^.*Apps ?Script.*$', 'Apps Script');
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
search | String | תבנית הביטוי הרגולרי לחיפוש |
replacement | String | הטקסט שבו רוצים להשתמש להחלפה |
חזרה
Element – הרכיב הנוכחי
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
setAttributes(attributes)
הגדרת המאפיינים של האלמנט.
פרמטר המאפיינים שצוין צריך להיות אובייקט שבו כל שם מאפיין הוא פריט בספירה DocumentApp.Attribute וכל ערך מאפיין הוא הערך החדש שיוחל.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Define a custom paragraph style. const style = {}; style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.RIGHT; style[DocumentApp.Attribute.FONT_FAMILY] = 'Calibri'; style[DocumentApp.Attribute.FONT_SIZE] = 18; style[DocumentApp.Attribute.BOLD] = true; // Append a plain paragraph. const par = body.appendParagraph('A paragraph with custom style.'); // Apply the custom style. par.setAttributes(style);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
attributes | Object | המאפיינים של האלמנט. |
חזרה
Table – הרכיב הנוכחי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
setBorderColor(color)
הגדרת צבע הגבול.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the first table. const table = body.getTables()[0]; // Sets the border color of the table to green. table.setBorderColor('#00FF00');
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
color | String | צבע הגבול, בפורמט של סימון CSS (למשל '#ffffff'). |
חזרה
Table – הרכיב הנוכחי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
setBorderWidth(width)
setColumnWidth(columnIndex, width)
מגדירה את הרוחב של העמודה שצוינה, בנקודות.
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
column | Integer | אינדקס העמודה |
width | Number | רוחב הגבול, בנקודות |
חזרה
Table – הרכיב הנוכחי
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
setLinkUrl(url)
setTextAlignment(textAlignment)
הגדרת יישור הטקסט. סוגי היישור הזמינים הם DocumentApp.TextAlignment.NORMAL, DocumentApp.TextAlignment.SUBSCRIPT ו-DocumentApp.TextAlignment.SUPERSCRIPT.
// Make the entire first paragraph in the active tab be superscript. const documentTab = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab(); const text = documentTab.getBody().getParagraphs()[0].editAsText(); text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
text | Text | סוג יישור הטקסט שרוצים להחיל |
חזרה
Table – הרכיב הנוכחי
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents