Class Table

טבלה

רכיב שמייצג טבלה. Table יכול להכיל רק רכיבי TableRow. למידע נוסף על מבנה מסמכים, קראו את המדריך להרחבת Google Docs.

כשיוצרים Table שמכיל מספר גדול של שורות או תאים, כדאי לבנות אותו ממערך מחרוזות כמו בדוגמה הבאה.

var body = DocumentApp.getActiveDocument().getBody();

// Create a two-dimensional array containing the cell contents.
var 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);

שיטות

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

// Gets the document body.
const body = doc.getBody();

// Gets the first table in the document 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).

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

var body = DocumentApp.getActiveDocument().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 - תוצאת חיפוש שמציינת את המיקום של רכיב החיפוש

הרשאות

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

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

findElement(elementType, from)

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

// Get the body section of the active document.
var body = DocumentApp.getActiveDocument().getBody();

// Define the search parameters.
var searchType = DocumentApp.ElementType.PARAGRAPH;
var searchHeading = DocumentApp.ParagraphHeading.HEADING1;
var searchResult = null;

// Search until the paragraph is found.
while (searchResult = body.findElement(searchType, searchResult)) {
  var par = searchResult.getElement().asParagraph();
  if (par.getHeading() == searchHeading) {
    // Found one, update and stop.
    par.setText('This is the first header.');
    return;
  }
}

פרמטרים

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

החזרות

RangeElement - תוצאת חיפוש שמציינת את המיקום הבא של רכיב החיפוש

הרשאות

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

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

findText(searchPattern)

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

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

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

פרמטרים

שםתיאורהתיאור
searchPatternStringהדפוס שצריך לחפש

החזרות

RangeElement - תוצאת חיפוש שמציינת את מיקום הטקסט לחיפוש, או הערך null אם אין התאמה

הרשאות

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

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

findText(searchPattern, from)

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

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

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

פרמטרים

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

החזרות

RangeElement - תוצאת חיפוש שמציינת את המיקום הבא של טקסט החיפוש, או הערך null אם אין התאמה

הרשאות

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

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

getAttributes()

מאחזר את מאפייני הרכיב.

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

var body = DocumentApp.getActiveDocument().getBody();

// Append a styled paragraph.
var par = body.appendParagraph('A bold, italicized paragraph.');
par.setBold(true);
par.setItalic(true);

// Retrieve the paragraph's attributes.
var atts = par.getAttributes();

// Log the paragraph attributes.
for (var 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('abc123456');

// Gets the document body.
const body = doc.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 - צבע הגבול, בפורמט של סימון 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('abc123456');

// Gets the document body.
const body = doc.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 – רוחב הגבול, בנקודות.

הרשאות

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

  • 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('abc123456');

// Gets the document body.
const body = doc.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 – התא בטבלה.

הרשאות

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

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

getChild(childIndex)

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

// Get the body section of the active document.
var body = DocumentApp.getActiveDocument().getBody();

// Obtain the first element in the document.
var 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('abc123456');

// Gets the document body.
const body = doc.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 – רוחב העמודה, בנקודות.

הרשאות

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

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

getLinkUrl()

אחזור של כתובת ה-URL של הקישור.

החזרות

String - כתובת ה-URL של הקישור, או הערך null אם הרכיב מכיל כמה ערכים למאפיין הזה

הרשאות

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

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

getNextSibling()

שולפת את הרכיב האח הבא של הרכיב.

לאח הבא יש אותו הורה והוא עוקב אחרי הרכיב הנוכחי.

החזרות

Element – הרכיב האח הבא.

הרשאות

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

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

getNumChildren()

אחזור מספר הילדים.

// Get the body section of the active document.
var body = DocumentApp.getActiveDocument().getBody();

// Log the number of elements in the document.
Logger.log("There are " + body.getNumChildren() +
    " elements in the document 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('abc123456');

// Gets the document body.
const body = doc.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 - רכיב ההורה.

הרשאות

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

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

getPreviousSibling()

אחזור הרכיב האח הקודם של הרכיב.

לפריט האח הקודם יש אותו הורה והוא מופיע לפני הרכיב הנוכחי.

החזרות

Element - רכיב האח הקודם.

הרשאות

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

  • 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('abc123456');

// Gets the document body.
const body = doc.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 – השורה בטבלה.

הרשאות

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

  • 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 אם הטקסט מכיל סוגים שונים של יישור טקסט או אם יישור הטקסט מעולם לא הוגדר

הרשאות

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

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

getType()

אחזור ה-ElementType של הרכיב.

השתמשו בפונקציה getType() כדי לקבוע את הסוג המדויק של רכיב נתון.

var body = DocumentApp.getActiveDocument().getBody();

// Obtain the first element in the document body.

var 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('abc123456');

// Gets the document body.
const body = doc.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()

מסיר את הרכיב מההורה שלו.

var body = DocumentApp.getActiveDocument().getBody();

// Remove all images in the document body.
var imgs = body.getImages();
for (var i = 0; i < imgs.length; i++) {
  imgs[i].removeFromParent();
}

החזרות

Table - הרכיב שהוסר.

הרשאות

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

  • 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('abc123456');

// Gets the document body.
const body = doc.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, שמגבילה את התחביר הנתמך.

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

var body = DocumentApp.getActiveDocument().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 וכל ערך של מאפיין הוא הערך החדש שיש להחיל.

var body = DocumentApp.getActiveDocument().getBody();

// Define a custom paragraph style.
var 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.
var 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('abc123456');

// Gets the document body.
const body = doc.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)

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

פרמטרים

שםתיאורהתיאור
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 be superscript.
var text = DocumentApp.getActiveDocument().getBody().getParagraphs()[0].editAsText();
text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);

פרמטרים

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

החזרות

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

הרשאות

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

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