Class Table

טבלה

רכיב שמייצג טבלה. רכיב 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

שיטהסוג הערך שמוחזרתיאור קצר
appendTableRow()TableRowיוצרת TableRow חדש ומצרפת אותו.
appendTableRow(tableRow)TableRowהוספה של TableRow שצוין.
clear()Tableמחיקת התוכן של הרכיב.
copy()Tableמחזירה עותק מנותק ועמוק של הרכיב הנוכחי.
editAsText()Textמקבלים גרסה Text של הרכיב הנוכחי לצורך עריכה.
findElement(elementType)RangeElement|nullמחפש בתוכן של הרכיב צאצא מסוג מסוים.
findElement(elementType, from)RangeElement|nullהפונקציה מחפשת בתוכן של הרכיב צאצא מסוג מסוים, החל מRangeElement שצוין.
findText(searchPattern)RangeElement|nullמחפשת בתוכן של הרכיב את תבנית הטקסט שצוינה באמצעות ביטויים רגולריים.
findText(searchPattern, from)RangeElement|nullמחפש בתוכן של הרכיב את תבנית הטקסט שצוינה, החל מתוצאת חיפוש נתונה.
getAttributes()Objectמאחזר את המאפיינים של האלמנט.
getBorderColor()String|nullמחזירה את צבע הגבול.
getBorderWidth()Number|nullמאחזרת את רוחב הגבול, בנקודות.
getCell(rowIndex, cellIndex)TableCell|nullאחזור הערך TableCell באינדקסים של השורה והתא שצוינו.
getChild(childIndex)Elementמאחזר את רכיב הצאצא באינדקס הצאצא שצוין.
getChildIndex(child)Integerמאחזר את אינדקס הצאצא של רכיב הצאצא שצוין.
getColumnWidth(columnIndex)Number|nullהפונקציה מאחזרת את רוחב העמודה שצוינה בטבלה, בנקודות.
getLinkUrl()String|nullהפונקציה מחזירה את כתובת ה-URL של הקישור.
getNextSibling()Element|nullמחזירה את רכיב האח הבא של הרכיב.
getNumChildren()Integerמאחזר את מספר הילדים.
getNumRows()Integerהפונקציה מאחזרת את מספר TableRows.
getParent()ContainerElement|nullמאחזר את אלמנט ההורה של האלמנט.
getPreviousSibling()Element|nullמאחזר את רכיב האח הקודם של הרכיב.
getRow(rowIndex)TableRow|nullמאחזרת את TableRow באינדקס השורה שצוין.
getText()Stringמאחזרת את התוכן של הרכיב כמחרוזת טקסט.
getTextAlignment()TextAlignment|nullמקבל את יישור הטקסט.
getType()ElementTypeאחזור ElementType של הרכיב.
insertTableRow(childIndex)TableRowיוצרת ומכניסה אובייקט TableRow חדש באינדקס שצוין.
insertTableRow(childIndex, tableRow)TableRowהפונקציה מוסיפה את TableRow שצוין באינדקס שצוין.
isAtDocumentEnd()Booleanההגדרה קובעת אם הרכיב נמצא בסוף Document.
removeChild(child)Tableהסרת רכיב הבן שצוין.
removeFromParent()Table|nullהפונקציה מסירה את הרכיב מהרכיב ההורה שלו.
removeRow(rowIndex)TableRowמסירה את TableRow באינדקס השורה שצוין.
replaceText(searchPattern, replacement)Elementהפונקציה מחליפה את כל המופעים של תבנית טקסט נתונה במחרוזת חלופית נתונה, באמצעות ביטויים רגולריים.
setAttributes(attributes)Tableהגדרת המאפיינים של האלמנט.
setBorderColor(color)Tableהגדרת צבע הגבול.
setBorderWidth(width)Tableמגדיר את רוחב הגבול, בנקודות.
setColumnWidth(columnIndex, width)Tableהפונקציה מגדירה את הרוחב של העמודה שצוינה, בנקודות.
setLinkUrl(url)Tableמגדיר את כתובת ה-URL של הקישור.
setTextAlignment(textAlignment)Tableהגדרת יישור הטקסט.

תיעוד מפורט

appendTableRow()

יוצרת TableRow חדש ומצרפת אותו.

חזרה

TableRow – רכיב השורה החדשה בטבלה

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

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

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);

פרמטרים

שםסוגתיאור
tableRowTableRowהשורה בטבלה שרוצים לצרף.

חזרה

TableRow — רכיב השורה בטבלה שנוסף.

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

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

clear()

מחיקת התוכן של הרכיב.

חזרה

Table – הרכיב הנוכחי.


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)

מחפש בתוכן של הרכיב צאצא מסוג מסוים.

פרמטרים

שםסוגתיאור
elementTypeElementTypeסוג הרכיב לחיפוש.

חזרה

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;
  }
}

פרמטרים

שםסוגתיאור
elementTypeElementTypeסוג הרכיב לחיפוש.
fromRangeElementתוצאת החיפוש שממנה מתחילים את החיפוש.

חזרה

RangeElement|null — תוצאת חיפוש שמציינת את המיקום הבא של רכיב החיפוש.

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

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

findText(searchPattern)

מחפשת בתוכן של הרכיב את תבנית הטקסט שצוינה באמצעות ביטויים רגולריים.

קבוצת משנה של תכונות הביטוי הרגולרי של JavaScript לא נתמכות באופן מלא, כמו קבוצות לכידה ומשני מצב.

תבנית הביטוי הרגולרי שצוינה מותאמת באופן עצמאי לכל בלוק טקסט שנכלל ברכיב הנוכחי.

פרמטרים

שםסוגתיאור
searchPatternStringהתבנית לחיפוש

חזרה

RangeElement|null – תוצאת חיפוש שמציינת את המיקום של טקסט החיפוש, או null אם אין התאמה

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

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

findText(searchPattern, from)

מחפש בתוכן של הרכיב את תבנית הטקסט שצוינה, החל מתוצאת חיפוש נתונה.

קבוצת משנה של תכונות הביטוי הרגולרי של JavaScript לא נתמכות באופן מלא, כמו קבוצות לכידה ומשני מצב.

תבנית הביטוי הרגולרי שצוינה מותאמת באופן עצמאי לכל בלוק טקסט שנכלל ברכיב הנוכחי.

פרמטרים

שםסוגתיאור
searchPatternStringהתבנית לחיפוש
fromRangeElementתוצאת החיפוש שממנה רוצים לחפש

חזרה

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());

פרמטרים

שםסוגתיאור
rowIndexIntegerהאינדקס של השורה שמכילה את התא שאותו רוצים לאחזר.
cellIndexIntegerהאינדקס של התא לאחזור.

חזרה

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.');
}

פרמטרים

שםסוגתיאור
childIndexIntegerהאינדקס של רכיב הצאצא לאחזור.

חזרה

Element – רכיב הצאצא באינדקס שצוין.

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

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

getChildIndex(child)

מאחזר את אינדקס הצאצא של רכיב הצאצא שצוין.

פרמטרים

שםסוגתיאור
childElementרכיב הצאצא שעבורו רוצים לאחזר את האינדקס.

חזרה

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));

פרמטרים

שםסוגתיאור
columnIndexIntegerאינדקס העמודות.

חזרה

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());

פרמטרים

שםסוגתיאור
rowIndexIntegerהאינדקס של השורה לאחזור.

חזרה

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 חדש באינדקס שצוין.

פרמטרים

שםסוגתיאור
childIndexIntegerהאינדקס שבו יתווסף הרכיב

חזרה

TableRow – הרכיב הנוכחי

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

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

insertTableRow(childIndex, tableRow)

הפונקציה מוסיפה את TableRow שצוין באינדקס שצוין.

פרמטרים

שםסוגתיאור
childIndexIntegerהאינדקס שבו יתווסף הרכיב
tableRowTableRowשורת הטבלה להוספה

חזרה

TableRow – רכיב שורת הטבלה שהוכנס

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

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

isAtDocumentEnd()

ההגדרה קובעת אם הרכיב נמצא בסוף Document.

חזרה

Boolean — אם הרכיב נמצא בסוף הכרטיסייה.

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

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

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());

פרמטרים

שםסוגתיאור
childElementרכיב הילד שרוצים להסיר.

חזרה

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);

פרמטרים

שםסוגתיאור
rowIndexIntegerהאינדקס של השורה שרוצים להסיר.

חזרה

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');

פרמטרים

שםסוגתיאור
searchPatternStringתבנית הביטוי הרגולרי לחיפוש
replacementStringהטקסט שבו רוצים להשתמש להחלפה

חזרה

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);

פרמטרים

שםסוגתיאור
attributesObjectהמאפיינים של הרכיב.

חזרה

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');

פרמטרים

שםסוגתיאור
colorStringצבע הגבול, בפורמט של סימון CSS (למשל '#ffffff').

חזרה

Table – הרכיב הנוכחי.

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

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

setBorderWidth(width)

מגדיר את רוחב הגבול, בנקודות.

פרמטרים

שםסוגתיאור
widthNumberרוחב הגבול, בנקודות

חזרה

Table – הרכיב הנוכחי

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

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

setColumnWidth(columnIndex, width)

הפונקציה מגדירה את הרוחב של העמודה שצוינה, בנקודות.

פרמטרים

שםסוגתיאור
columnIndexIntegerאינדקס העמודה
widthNumberרוחב הגבול, בנקודות

חזרה

Table – הרכיב הנוכחי

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

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

setLinkUrl(url)

מגדיר את כתובת ה-URL של הקישור.

פרמטרים

שםסוגתיאור
urlStringכתובת ה-URL של הקישור

חזרה

Table – הרכיב הנוכחי

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

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

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);

פרמטרים

שםסוגתיאור
textAlignmentTextAlignmentסוג יישור הטקסט שרוצים להחיל

חזרה

Table – הרכיב הנוכחי

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

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