רכיב שמייצג טבלה. 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()
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);
פרמטרים
שם | תיאור | התיאור |
---|---|---|
tableRow | TableRow | השורה בטבלה שצריך לצרף. |
החזרות
TableRow
- הרכיב של השורה המצורפת בטבלה.
הרשאות
לסקריפטים שמשתמשים בשיטה הזו נדרשת הרשאה באחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
clear()
copy()
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)
מחפשת צאצא מהסוג שצוין.
פרמטרים
שם | תיאור | התיאור |
---|---|---|
elementType | ElementType | סוג הרכיב שיש לחפש |
החזרות
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; } }
פרמטרים
שם | תיאור | התיאור |
---|---|---|
elementType | ElementType | סוג הרכיב שיש לחפש |
from | RangeElement | תוצאת החיפוש שממנה יש לחפש |
החזרות
RangeElement
- תוצאת חיפוש שמציינת את המיקום הבא של רכיב החיפוש
הרשאות
לסקריפטים שמשתמשים בשיטה הזו נדרשת הרשאה באחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
findText(searchPattern)
מחפש את תוכן הרכיב כדי לאתר את דפוס הטקסט שצוין באמצעות ביטויים רגולריים.
אין תמיכה מלאה בקבוצת משנה של תכונות של ביטויים רגולריים ב-JavaScript, כמו קבוצות צילום ומגבילי מצב.
הדפוס של הביטוי הרגולרי שסופק מותאם בנפרד לכל גוש טקסט שכלול ברכיב הנוכחי.
פרמטרים
שם | תיאור | התיאור |
---|---|---|
searchPattern | String | הדפוס שצריך לחפש |
החזרות
RangeElement
- תוצאת חיפוש שמציינת את מיקום הטקסט לחיפוש, או הערך null אם אין
התאמה
הרשאות
לסקריפטים שמשתמשים בשיטה הזו נדרשת הרשאה באחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
findText(searchPattern, from)
מחפש את תוכן הרכיב לפי דפוס הטקסט שצוין, החל מתוצאת חיפוש נתונה.
אין תמיכה מלאה בקבוצת משנה של תכונות של ביטויים רגולריים ב-JavaScript, כמו קבוצות צילום ומגבילי מצב.
הדפוס של הביטוי הרגולרי שסופק מותאם בנפרד לכל גוש טקסט שכלול ברכיב הנוכחי.
פרמטרים
שם | תיאור | התיאור |
---|---|---|
searchPattern | String | הדפוס שצריך לחפש |
from | RangeElement | תוצאת החיפוש שממנה יש לחפש |
החזרות
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());
פרמטרים
שם | תיאור | התיאור |
---|---|---|
rowIndex | Integer | האינדקס של השורה שמכילה את התא שיש לאחזר. |
cellIndex | Integer | האינדקס של התא שיש לאחזר. |
החזרות
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."); }
פרמטרים
שם | תיאור | התיאור |
---|---|---|
childIndex | 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('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));
פרמטרים
שם | תיאור | התיאור |
---|---|---|
columnIndex | Integer | אינדקס העמודה. |
החזרות
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()
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()
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());
פרמטרים
שם | תיאור | התיאור |
---|---|---|
rowIndex | Integer | האינדקס של השורה שיש לאחזר. |
החזרות
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
חדש באינדקס שצוין.
פרמטרים
שם | תיאור | התיאור |
---|---|---|
childIndex | Integer | את האינדקס שבו יש להכניס את הרכיב |
החזרות
TableRow
- הרכיב הנוכחי
הרשאות
לסקריפטים שמשתמשים בשיטה הזו נדרשת הרשאה באחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertTableRow(childIndex, tableRow)
הפונקציה מוסיפה את הערך הנתון TableRow
באינדקס שצוין.
פרמטרים
שם | תיאור | התיאור |
---|---|---|
childIndex | Integer | את האינדקס שבו יש להכניס את הרכיב |
tableRow | TableRow | שורת הטבלה להוספה |
החזרות
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('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());
פרמטרים
שם | תיאור | התיאור |
---|---|---|
child | Element | רכיב הצאצא שיש להסיר. |
החזרות
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);
פרמטרים
שם | תיאור | התיאור |
---|---|---|
rowIndex | Integer | האינדקס של השורה שיש להסיר. |
החזרות
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");
פרמטרים
שם | תיאור | התיאור |
---|---|---|
searchPattern | String | את הדפוס הרגולרי שצריך לחפש |
replacement | String | בטקסט שישמש כתחליף |
החזרות
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);
פרמטרים
שם | תיאור | התיאור |
---|---|---|
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('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');
פרמטרים
שם | תיאור | התיאור |
---|---|---|
color | String | צבע הגבול, בפורמט של סימון CSS (כגון '#ffffff' ). |
החזרות
Table
- הרכיב הנוכחי.
הרשאות
לסקריפטים שמשתמשים בשיטה הזו נדרשת הרשאה באחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setBorderWidth(width)
setColumnWidth(columnIndex, width)
מגדירה את רוחב העמודה שצוינה, בנקודות.
פרמטרים
שם | תיאור | התיאור |
---|---|---|
columnIndex | 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 be superscript. var text = DocumentApp.getActiveDocument().getBody().getParagraphs()[0].editAsText(); text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);
פרמטרים
שם | תיאור | התיאור |
---|---|---|
textAlignment | TextAlignment | סוג היישור של הטקסט שצריך להחיל |
החזרות
Table
- הרכיב הנוכחי
הרשאות
לסקריפטים שמשתמשים בשיטה הזו נדרשת הרשאה באחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents