רכיב שמייצג טבלה. רכיב Table יכול להכיל רק רכיבי Table. מידע נוסף על מבנה המסמך זמין במדריך להרחבת 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 | הגדרת יישור הטקסט. |
תיעוד מפורט
append Table Row()
append Table Row(tableRow)
הוספה של Table שצוין.
// 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 | השורה בטבלה שרוצים לצרף. |
חזרה
Table — רכיב השורה בטבלה שנוסף.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
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
edit As Text()
מקבלים גרסה Text של הרכיב הנוכחי לצורך עריכה.
משתמשים ב-edit כדי לשנות את תוכן הרכיבים כטקסט עשיר. במצב edit המערכת מתעלמת מאלמנטים שהם לא טקסט (כמו Inline ו-Horizontal).
רכיבי צאצא שכלולים באופן מלא בטווח טקסט שנמחק מוסרים מהרכיב.
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 – גרסת טקסט של הרכיב הנוכחי
find Element(elementType)
מחפש בתוכן של הרכיב צאצא מסוג מסוים.
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
element | Element | סוג הרכיב לחיפוש. |
חזרה
Range — תוצאת חיפוש שמציינת את המיקום של רכיב החיפוש.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
find Element(elementType, from)
הפונקציה מחפשת בתוכן של הרכיב צאצא מסוג מסוים, החל מRange שצוין.
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 | תוצאת החיפוש שממנה מתחילים את החיפוש. |
חזרה
Range — תוצאת חיפוש שמציינת את המיקום הבא של רכיב החיפוש.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
find Text(searchPattern)
מחפשת בתוכן של הרכיב את תבנית הטקסט שצוינה באמצעות ביטויים רגולריים.
קבוצת משנה של תכונות הביטוי הרגולרי של JavaScript לא נתמכות באופן מלא, כמו קבוצות לכידה ומשני מצב.
תבנית הביטוי הרגולרי שצוינה מותאמת באופן עצמאי לכל בלוק טקסט שנכלל ברכיב הנוכחי.
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
search | String | התבנית לחיפוש |
חזרה
Range – תוצאת חיפוש שמציינת את המיקום של טקסט החיפוש, או null אם אין התאמה
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
find Text(searchPattern, from)
מחפש בתוכן של הרכיב את תבנית הטקסט שצוינה, החל מתוצאת חיפוש נתונה.
קבוצת משנה של תכונות הביטוי הרגולרי של JavaScript לא נתמכות באופן מלא, כמו קבוצות לכידה ומשני מצב.
תבנית הביטוי הרגולרי שצוינה מותאמת באופן עצמאי לכל בלוק טקסט שנכלל ברכיב הנוכחי.
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
search | String | התבנית לחיפוש |
from | Range | תוצאת החיפוש שממנה רוצים לחפש |
חזרה
Range — תוצאת חיפוש שמציינת את המיקום הבא של טקסט החיפוש, או null אם אין התאמה
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Attributes()
מאחזר את המאפיינים של האלמנט.
התוצאה היא אובייקט שמכיל מאפיין לכל מאפיין תקין של רכיב, כאשר כל שם מאפיין תואם לפריט בספירה Document.
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
get Border 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 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
get Border Width()
מאחזרת את רוחב הגבול, בנקודות.
// 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
get Cell(rowIndex, cellIndex)
אחזור הערך Table באינדקסים של השורה והתא שצוינו.
// 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 | האינדקס של התא לאחזור. |
חזרה
Table – התא בטבלה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Child(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
get Child Index(child)
מאחזר את אינדקס הצאצא של רכיב הצאצא שצוין.
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
child | Element | רכיב הצאצא שעבורו רוצים לאחזר את האינדקס. |
חזרה
Integer — אינדקס הילד.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Column Width(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
get Link Url()
הפונקציה מחזירה את כתובת ה-URL של הקישור.
חזרה
String|null – כתובת ה-URL של הקישור, או null אם הרכיב מכיל כמה ערכים למאפיין הזה
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Next Sibling()
מחזירה את רכיב האח הבא של הרכיב.
לרכיב הבא באותה רמה יש את אותו רכיב אב והוא מופיע אחרי הרכיב הנוכחי.
חזרה
Element|null – הרכיב הבא באותה רמה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Num Children()
מאחזר את מספר הילדים.
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
get Num Rows()
הפונקציה מאחזרת את מספר Table.
// 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
get Parent()
מאחזר את אלמנט ההורה של האלמנט.
רכיב ההורה מכיל את הרכיב הנוכחי.
חזרה
Container – רכיב ההורה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Previous Sibling()
מאחזר את רכיב האח הקודם של הרכיב.
האלמנט הקודם באותה רמה הוא אלמנט עם אותו אלמנט אב, שמופיע לפני האלמנט הנוכחי.
חזרה
Element|null – רכיב האח הקודם.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Row(rowIndex)
מאחזרת את Table באינדקס השורה שצוין.
// 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 | האינדקס של השורה לאחזור. |
חזרה
Table — השורה בטבלה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Text()
מאחזרת את התוכן של הרכיב כמחרוזת טקסט.
חזרה
String – התוכן של הרכיב כמחרוזת טקסט
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Text Alignment()
מקבל את יישור הטקסט. סוגי היישור הזמינים הם Document, Document ו-Document.
חזרה
Text – סוג יישור הטקסט, או null אם הטקסט מכיל כמה סוגים של יישור טקסט או אם יישור הטקסט לא הוגדר אף פעם
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Type()
אחזור Element של הרכיב.
משתמשים ב-get כדי לקבוע את הסוג המדויק של רכיב נתון.
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.'); }
חזרה
Element – סוג הרכיב.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
insert Table Row(childIndex)
יוצרת ומכניסה אובייקט Table חדש באינדקס שצוין.
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
child | Integer | האינדקס שבו יתווסף הרכיב |
חזרה
Table – הרכיב הנוכחי
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
insert Table Row(childIndex, tableRow)
הפונקציה מוסיפה את Table שצוין באינדקס שצוין.
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
child | Integer | האינדקס שבו יתווסף הרכיב |
table | Table | שורת הטבלה להוספה |
חזרה
Table – רכיב שורת הטבלה שהוכנס
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
is At Document End()
remove Child(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
remove From Parent()
הפונקציה מסירה את הרכיב מהרכיב ההורה שלו.
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
remove Row(rowIndex)
מסירה את Table באינדקס השורה שצוין.
// 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 | האינדקס של השורה שרוצים להסיר. |
חזרה
Table – השורה שהוסרה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
replace Text(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
set Attributes(attributes)
הגדרת המאפיינים של האלמנט.
פרמטר המאפיינים שצוין צריך להיות אובייקט שבו כל שם מאפיין הוא פריט בספירה Document וכל ערך מאפיין הוא הערך החדש שיוחל.
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
set Border Color(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
set Border Width(width)
set Column Width(columnIndex, width)
הפונקציה מגדירה את הרוחב של העמודה שצוינה, בנקודות.
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
column | Integer | אינדקס העמודה |
width | Number | רוחב הגבול, בנקודות |
חזרה
Table – הרכיב הנוכחי
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Link Url(url)
set Text Alignment(textAlignment)
הגדרת יישור הטקסט. סוגי היישור הזמינים הם Document, Document ו-Document.
// 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