רכיב שמייצג אזור של טקסט עשיר. כל הטקסט בתג Document מופיע בתוך רכיבי Text.
רכיב Text יכול להיכלל ברכיב Equation, Equation, List או Paragraph, אבל הוא עצמו לא יכול להכיל רכיב אחר. למידע נוסף על מבנה המסמך, אפשר לעיין במדריך להרחבת Google Docs.
// Gets the body contents of the active tab. const body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody(); // Use editAsText to obtain a single text element containing // all the characters in the tab. const text = body.editAsText(); // Insert text at the beginning of the tab. text.insertText(0, 'Inserted text.\n'); // Insert text at the end of the tab. text.appendText('\nAppended text.'); // Make the first half of the tab blue. text.setForegroundColor(0, text.getText().length / 2, '#00FFFF');
Methods
| שיטה | סוג הערך שמוחזר | תיאור קצר |
|---|---|---|
append | Text | הוספת הטקסט שצוין לסוף אזור הטקסט הזה. |
copy() | Text | מחזירה עותק מנותק ועמוק של הרכיב הנוכחי. |
delete | Text | מחיקת טווח של טקסט. |
edit | Text | מקבלים גרסה Text של הרכיב הנוכחי לצורך עריכה. |
find | Range | מחפשת בתוכן של הרכיב את תבנית הטקסט שצוינה באמצעות ביטויים רגולריים. |
find | Range | מחפש בתוכן של הרכיב את תבנית הטקסט שצוינה, החל מתוצאת חיפוש נתונה. |
get | Object | מאחזר את המאפיינים של האלמנט. |
get | Object | הפונקציה מאחזרת את המאפיינים בהיסט התווים שצוין. |
get | String|null | מאחזר את הגדרת צבע הרקע. |
get | String|null | מאחזרת את צבע הרקע בהיסט התווים שצוין. |
get | String|null | מאחזר את ההגדרה של משפחת הגופנים. |
get | String|null | הפונקציה מאחזרת את משפחת הגופנים בהיסט התווים שצוין. |
get | Number|null | מאחזר את ההגדרה של גודל הגופן. |
get | Number|null | הפונקציה מאחזרת את גודל הגופן בהיסט התווים שצוין. |
get | String|null | מאחזר את הגדרת צבע החזית. |
get | String|null | הפונקציה מאחזרת את צבע החזית במיקום התו שצוין. |
get | String|null | הפונקציה מחזירה את כתובת ה-URL של הקישור. |
get | String|null | הפונקציה מאחזרת את כתובת ה-URL של הקישור בהיסט התווים שצוין. |
get | Element|null | מחזירה את רכיב האח הבא של הרכיב. |
get | Container | מאחזר את אלמנט ההורה של האלמנט. |
get | Element|null | מאחזר את רכיב האח הקודם של הרכיב. |
get | String | מאחזרת את התוכן של הרכיב כמחרוזת טקסט. |
get | Text | מקבל את יישור הטקסט. |
get | Text | מקבלת את יישור הטקסט של תו יחיד. |
get | Integer[] | מאחזר את קבוצת אינדקסים של טקסט שתואמים להתחלה של רצפים נפרדים של עיצוב טקסט. |
get | Element | אחזור Element של הרכיב. |
insert | Text | הפונקציה מוסיפה את הטקסט שצוין בהיסט התווים שצוין. |
is | Boolean | ההגדרה קובעת אם הרכיב נמצא בסוף Document. |
is | Boolean|null | מאחזר את ההגדרה של הטקסט המודגש. |
is | Boolean|null | אחזור הגדרת ההדגשה בהיסט התווים שצוין. |
is | Boolean|null | מאחזר את ההגדרה של הטקסט המוטה. |
is | Boolean|null | אחזור ההגדרה של הטיית הטקסט במיקום התו שצוין. |
is | Boolean|null | מאחזר את הגדרת הקו החוצה. |
is | Boolean|null | הפונקציה מאחזרת את הגדרת הקו החוצה במיקום התו שצוין. |
is | Boolean|null | מאחזר את הגדרת הקו התחתון. |
is | Boolean|null | הפונקציה מאחזרת את הגדרת הקו התחתון במיקום התו שצוין. |
merge() | Text|null | מיזוג הרכיב עם הרכיב הקודם מאותו סוג. |
remove | Text|null | הפונקציה מסירה את הרכיב מהרכיב ההורה שלו. |
replace | Element | הפונקציה מחליפה את כל המופעים של תבנית טקסט נתונה במחרוזת חלופית נתונה, באמצעות ביטויים רגולריים. |
set | Text | הפונקציה מחילה את המאפיינים שצוינו על טווח התווים הנתון. |
set | Text | הגדרת המאפיינים של האלמנט. |
set | Text | הגדרת צבע הרקע לטווח התווים שצוין. |
set | Text | הגדרת צבע הרקע. |
set | Text | הגדרת ההדגשה. |
set | Text | הגדרת ההדגשה לטווח התווים שצוין. |
set | Text | הגדרת משפחת הגופנים לטווח התווים שצוין. |
set | Text | הגדרת משפחת הגופנים. |
set | Text | הגדרת גודל הגופן לטווח התווים שצוין. |
set | Text | הגדרת גודל הגופן. |
set | Text | הגדרת צבע החזית לטווח התווים שצוין. |
set | Text | הגדרת צבע החזית. |
set | Text | הגדרת ההטיה. |
set | Text | הגדרת ההטיה של טווח התווים שצוין. |
set | Text | הגדרת כתובת ה-URL של הקישור לטווח התווים שצוין. |
set | Text | מגדיר את כתובת ה-URL של הקישור. |
set | Text | הגדרת הקו החוצה. |
set | Text | הגדרת קו חוצה לטווח התווים שצוין. |
set | Text | מגדיר את תוכן הטקסט. |
set | Text | הגדרת יישור הטקסט לטווח תווים נתון. |
set | Text | הגדרת יישור הטקסט. |
set | Text | הגדרת הקו התחתון. |
set | Text | הגדרת הקו התחתון לטווח התווים שצוין. |
תיעוד מפורט
append Text(text)
הוספת הטקסט שצוין לסוף אזור הטקסט הזה.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Adds the text, 'Sample body text,' to the end of the tab body. const text = body.editAsText().appendText('Sample body text');
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
text | String | הטקסט לצירוף. |
חזרה
Text – הרכיב הנוכחי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
copy()
מחזירה עותק מנותק ועמוק של הרכיב הנוכחי.
כל רכיבי הצאצא שקיימים ברכיב מועתקים גם הם. לאלמנט החדש אין אלמנט אב.
חזרה
Text – העותק החדש.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
delete Text(startOffset, endOffsetInclusive)
מחיקת טווח של טקסט.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Deletes the first 10 characters in the body. const text = body.editAsText().deleteText(0, 9);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
start | Integer | ההיסט של התו הראשון שרוצים למחוק. |
end | Integer | ההיסט של התו האחרון שרוצים למחוק. |
חזרה
Text – הרכיב הנוכחי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
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 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 Attributes(offset)
הפונקציה מאחזרת את המאפיינים בהיסט התווים שצוין.
התוצאה היא אובייקט שמכיל מאפיין לכל מאפיין טקסט תקין, כאשר כל שם מאפיין תואם לפריט בספירה Document.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Declares style attributes. const style = {}; style[DocumentApp.Attribute.BOLD] = true; style[DocumentApp.Attribute.ITALIC] = true; style[DocumentApp.Attribute.FONT_SIZE] = 29; // Sets the style attributes to the tab's body. const text = body.editAsText(); text.setAttributes(style); // Gets the style attributes applied to the eleventh character in the // body and logs them to the console. const attributes = text.getAttributes(10); console.log(attributes);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
offset | Integer | ההיסט של התו. |
חזרה
Object – מאפייני הרכיב.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Background Color()
מאחזר את הגדרת צבע הרקע.
חזרה
String|null – צבע הרקע, בפורמט של סימון CSS (כמו '#ffffff'), או null
אם הרכיב מכיל כמה ערכים למאפיין הזה
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Background Color(offset)
מאחזרת את צבע הרקע בהיסט התווים שצוין.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID', ); // 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(); // Sets the background color of the first 3 characters in the body. const text = body.editAsText().setBackgroundColor(0, 2, '#FFC0CB'); // Gets the background color of the first character in the body. const backgroundColor = text.getBackgroundColor(0); // Logs the background color to the console. console.log(backgroundColor);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
offset | Integer | ההיסט של התו. |
חזרה
String|null — צבע הרקע, בפורמט של סימון CSS (כמו '#ffffff').
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Font Family()
מאחזר את ההגדרה של משפחת הגופנים. השם יכול להיות כל גופן מהתפריט 'גופן' ב-Docs או מ-Google Fonts, והוא תלוי אותיות רישיות וקטנות. השיטות get ו-set משתמשות עכשיו בשמות מחרוזות לגופנים במקום ב-enum . למרות שהספירה הזו הוצאה משימוש, היא תישאר זמינה לצורך תאימות לסקריפטים ישנים.Font
חזרה
String|null – משפחת הגופנים, או null אם הרכיב מכיל כמה ערכים למאפיין הזה
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Font Family(offset)
הפונקציה מאחזרת את משפחת הגופנים בהיסט התווים שצוין. השם יכול להיות כל גופן מהתפריט Font ב-Docs או מ-Google Fonts, והוא תלוי באותיות רישיות. השיטות get ו-set
משתמשות עכשיו בשמות מחרוזות לגופנים במקום ב-enum . למרות שהספירה הזו הוצאה משימוש, היא תישאר זמינה לצורך תאימות לסקריפטים ישנים.
Font
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Sets the font of the first 16 characters to Impact. const text = body.editAsText().setFontFamily(0, 15, 'Impact'); // Gets the font family of the 16th character in the tab body. const fontFamily = text.getFontFamily(15); // Logs the font family to the console. console.log(fontFamily);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
offset | Integer | ההיסט של התו. |
חזרה
String|null — משפחת הגופנים.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Font Size()
מאחזר את ההגדרה של גודל הגופן.
חזרה
Number|null – גודל הגופן, או null אם הרכיב מכיל כמה ערכים למאפיין הזה
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Font Size(offset)
הפונקציה מאחזרת את גודל הגופן בהיסט התווים שצוין.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Sets the font size of the first 13 characters to 15. const text = body.editAsText().setFontSize(0, 12, 15); // Gets the font size of the first character. const fontSize = text.getFontSize(0); // Logs the font size to the console. console.log(fontSize);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
offset | Integer | ההיסט של התו. |
חזרה
Number|null — גודל הגופן.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Foreground Color()
מאחזר את הגדרת צבע החזית.
חזרה
String|null – צבע החזית, בפורמט של סימון CSS (לדוגמה, '#ffffff'), או null
אם הרכיב מכיל כמה ערכים למאפיין הזה
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Foreground Color(offset)
הפונקציה מאחזרת את צבע החזית במיקום התו שצוין.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Sets the foreground color of the first 3 characters in the tab body. const text = body.editAsText().setForegroundColor(0, 2, '#0000FF'); // Gets the foreground color of the first character in the tab body. const foregroundColor = text.getForegroundColor(0); // Logs the foreground color to the console. console.log(foregroundColor);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
offset | Integer | ההיסט של התו. |
חזרה
String|null – צבע החזית, בפורמט של סימון CSS (למשל '#ffffff').
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
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 Link Url(offset)
הפונקציה מאחזרת את כתובת ה-URL של הקישור בהיסט התווים שצוין.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Applies a link to the first 10 characters in the body. const text = body.editAsText().setLinkUrl(0, 9, 'https://www.example.com/'); // Gets the URL of the link from the first character. const link = text.getLinkUrl(0); // Logs the link URL to the console. console.log(link);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
offset | Integer | ההיסט של התו. |
חזרה
String|null — כתובת ה-URL של הקישור.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
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 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 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 Text Alignment(offset)
מקבלת את יישור הטקסט של תו יחיד. סוגי היישור הזמינים הם Document, Document ו-Document.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Sets the text alignment of the tab's body to NORMAL. const text = body.editAsText().setTextAlignment(DocumentApp.TextAlignment.NORMAL); // Gets the text alignment of the ninth character. const alignment = text.getTextAlignment(8); // Logs the text alignment to the console. console.log(alignment.toString());
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
offset | Integer | ההיסט של התו. |
חזרה
Text – סוג יישור הטקסט, או null אם יישור הטקסט מעולם לא הוגדר.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Text Attribute Indices()
מאחזר את קבוצת אינדקסים של טקסט שתואמים להתחלה של רצפים נפרדים של עיצוב טקסט.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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 text indices at which text formatting changes. const indices = body.editAsText().getTextAttributeIndices(); // Logs the indices to the console. console.log(indices.toString());
חזרה
Integer[] — קבוצת האינדקסים של הטקסט שבהם משתנה עיצוב הטקסט.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
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 Text(offset, text)
הפונקציה מוסיפה את הטקסט שצוין בהיסט התווים שצוין.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Inserts the text, 'Sample inserted text', at the start of the body content. const text = body.editAsText().insertText(0, 'Sample inserted text');
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
offset | Integer | ההיסט של התו שבו רוצים להוסיף את הטקסט. |
text | String | הטקסט להוספה. |
חזרה
Text – הרכיב הנוכחי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
is At Document End()
is Bold()
מאחזר את ההגדרה של הטקסט המודגש.
חזרה
Boolean|null – האם הטקסט מודגש, או null אם הרכיב מכיל כמה ערכים למאפיין הזה
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
is Bold(offset)
אחזור הגדרת ההדגשה בהיסט התווים שצוין.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Bolds the first 4 characters in the tab body. const text = body.editAsText().setBold(0, 3, true); // Gets whether or not the text is bold. const bold = text.editAsText().isBold(0); // Logs the text's bold setting to the console console.log(bold);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
offset | Integer | ההיסט של התו. |
חזרה
Boolean|null — ההגדרה להדגשה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
is Italic()
מאחזר את ההגדרה של הטקסט הנטוי.
חזרה
Boolean|null – האם הטקסט מוטה, או null אם הרכיב מכיל כמה ערכים למאפיין הזה
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
is Italic(offset)
אחזור ההגדרה של הטיית הטקסט במיקום התו שצוין.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Sets the first 13 characters of the tab body to italic. const text = body.editAsText().setItalic(0, 12, true); // Gets whether the fifth character in the tab body is set to // italic and logs it to the console. const italic = text.isItalic(4); console.log(italic);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
offset | Integer | ההיסט של התו. |
חזרה
Boolean|null — ההגדרה של הטקסט הנטוי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
is Strikethrough()
מאחזר את הגדרת הקו החוצה.
חזרה
Boolean|null – האם הטקסט הוא קו חוצה, או null אם הרכיב מכיל כמה ערכים של המאפיין הזה
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
is Strikethrough(offset)
הפונקציה מאחזרת את הגדרת הקו החוצה במיקום התו שצוין.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Sets the first 17 characters of the tab body to strikethrough. const text = body.editAsText().setStrikethrough(0, 16, true); // Gets whether the first character in the tab body is set to // strikethrough and logs it to the console. const strikethrough = text.isStrikethrough(0); console.log(strikethrough);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
offset | Integer | ההיסט של התו. |
חזרה
Boolean|null — הגדרת הקו החוצה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
is Underline()
מאחזר את הגדרת הקו התחתון.
חזרה
Boolean|null – אם הטקסט מודגש או הערך null אם הרכיב מכיל כמה ערכים של המאפיין הזה
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
is Underline(offset)
הפונקציה מאחזרת את הגדרת הקו התחתון במיקום התו שצוין.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Sets the first 13 characters of the tab body to underline. const text = body.editAsText().setUnderline(0, 12, false); // Gets whether the first character in the tab body is set to // underline and logs it to the console const underline = text.editAsText().isUnderline(0); console.log(underline);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
offset | Integer | ההיסט של התו. |
חזרה
Boolean|null — הגדרת הקו התחתון.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
merge()
מיזוג הרכיב עם הרכיב הקודם מאותו סוג.
אפשר למזג רק רכיבים מאותו סוג Element. כל רכיבי הצאצא שנכללים ברכיב הנוכחי מועברים לרכיב האח הקודם.
האלמנט הנוכחי יוסר מהמסמך.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Example 1: Merge paragraphs // Append two paragraphs to the document's active tab. const par1 = body.appendParagraph('Paragraph 1.'); const par2 = body.appendParagraph('Paragraph 2.'); // Merge the newly added paragraphs into a single paragraph. par2.merge(); // Example 2: Merge table cells // Create a two-dimensional array containing the table's 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. const table = body.appendTable(cells); // Get the first row in the table. const row = table.getRow(0); // Get the two cells in this row. const cell1 = row.getCell(0); const cell2 = row.getCell(1); // Merge the current cell into its preceding sibling element. const merged = cell2.merge();
חזרה
Text|null – הרכיב הממוזג.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
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(); }
חזרה
Text|null — הרכיב שהוסר.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
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(startOffset, endOffsetInclusive, attributes)
הפונקציה מחילה את המאפיינים שצוינו על טווח התווים הנתון.
פרמטר המאפיינים שצוין צריך להיות אובייקט שבו כל שם מאפיין הוא פריט בספירה Document וכל ערך מאפיין הוא הערך החדש שיוחל.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Declares style attributes for font size and font family. const style = {}; style[DocumentApp.Attribute.FONT_SIZE] = 20; style[DocumentApp.Attribute.FONT_FAMILY] = 'Impact'; // Sets the style attributes to the first 9 characters in the tab's body. const text = body.setAttributes(0, 8, style);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
start | Integer | היסט ההתחלה של טווח הטקסט. |
end | Integer | ההיסט של סוף טווח הטקסט. |
attributes | Object | המאפיינים של הרכיב. |
חזרה
Text – הרכיב הנוכחי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
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 | המאפיינים של הרכיב. |
חזרה
Text – הרכיב הנוכחי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Background Color(startOffset, endOffsetInclusive, color)
הגדרת צבע הרקע לטווח התווים שצוין.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Sets the background color of the first 3 characters in the // tab body to hex color #0000FF. const text = body.editAsText().setBackgroundColor(0, 2, '#0000FF');
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
start | Integer | היסט ההתחלה של טווח הטקסט. |
end | Integer | ההיסט של סוף טווח הטקסט. |
color | String | צבע הרקע, בפורמט של סימון CSS (לדוגמה, '#ffffff'). |
חזרה
Text – הרכיב הנוכחי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Background Color(color)
set Bold(bold)
set Bold(startOffset, endOffsetInclusive, bold)
הגדרת ההדגשה לטווח התווים שצוין.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Sets the first 11 characters in the tab's body to bold. const text = body.editAsText().setBold(0, 10, true);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
start | Integer | היסט ההתחלה של טווח הטקסט. |
end | Integer | ההיסט של סוף טווח הטקסט. |
bold | Boolean | ההגדרה של הדגשה. |
חזרה
Text – הרכיב הנוכחי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Font Family(startOffset, endOffsetInclusive, fontFamilyName)
הגדרת משפחת הגופנים לטווח התווים שצוין. השם יכול להיות כל גופן מהתפריט Font (גופן) ב-Docs או מ-Google Fonts, והוא תלוי אותיות רישיות.
שמות גופנים לא מזוהים יוצגו כ-Arial. השיטות get ו-set משתמשות עכשיו בשמות מחרוזות לגופנים במקום ב-enum . למרות שהספירה הזו הוצאה משימוש, היא תישאר זמינה לצורך תאימות לסקריפטים ישנים.
Font
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Sets the font of the first 4 characters in the tab's body to Roboto. const text = body.editAsText().setFontFamily(0, 3, 'Roboto');
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
start | Integer | היסט ההתחלה של טווח הטקסט. |
end | Integer | ההיסט של סוף טווח הטקסט. |
font | String | השם של משפחת הגופנים, מתוך תפריט הגופנים ב-Docs או בגופנים של Google. |
חזרה
Text – הרכיב הנוכחי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Font Family(fontFamilyName)
הגדרת משפחת הגופנים. השם יכול להיות כל גופן מהתפריט 'גופן' ב-Docs או מ-Google Fonts, והוא תלוי אותיות רישיות וקטנות. שמות של גופנים לא מזוהים יוצגו כ-Arial. השיטות get ו-set משתמשות עכשיו בשמות מחרוזות לגופנים במקום ב-enum . למרות שהספירה הזו הוצאה משימוש, היא תישאר זמינה לצורך תאימות לסקריפטים ישנים.Font
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
font | String | השם של משפחת הגופנים, מתוך תפריט הגופנים ב-Docs או בגופנים של Google |
חזרה
Text – הרכיב הנוכחי
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Font Size(startOffset, endOffsetInclusive, size)
הגדרת גודל הגופן לטווח התווים שצוין.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Sets the size of the first 11 characters in the tab's body to 12. const text = body.editAsText().setFontSize(0, 10, 12);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
start | Integer | היסט ההתחלה של טווח הטקסט. |
end | Integer | ההיסט של סוף טווח הטקסט. |
size | Number | גודל הגופן. |
חזרה
Text – הרכיב הנוכחי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Font Size(size)
set Foreground Color(startOffset, endOffsetInclusive, color)
הגדרת צבע החזית לטווח התווים שצוין.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Sets the foreground color of the first 2 characters in the // tab's body to hex color #FF0000. const text = body.editAsText().setForegroundColor(0, 1, '#FF0000'); // Gets the foreground color for the second character in the tab's body. const foregroundColor = text.getForegroundColor(1); // Logs the foreground color to the console. console.log(foregroundColor);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
start | Integer | היסט ההתחלה של טווח הטקסט. |
end | Integer | ההיסט של סוף טווח הטקסט. |
color | String | צבע החזית, בפורמט של סימון CSS (למשל '#ffffff'). |
חזרה
Text – הרכיב הנוכחי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Foreground Color(color)
set Italic(italic)
set Italic(startOffset, endOffsetInclusive, italic)
הגדרת ההטיה של טווח התווים שצוין.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Sets the first 11 characters in the tab's body to italic. const text = body.editAsText().setItalic(0, 10, true);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
start | Integer | היסט ההתחלה של טווח הטקסט. |
end | Integer | ההיסט של סוף טווח הטקסט. |
italic | Boolean | הגדרת הנטייה. |
חזרה
Text – הרכיב הנוכחי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Link Url(startOffset, endOffsetInclusive, url)
הגדרת כתובת ה-URL של הקישור לטווח התווים שצוין.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Applies a link to the first 11 characters in the body. const text = body.editAsText().setLinkUrl(0, 10, 'https://example.com');
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
start | Integer | היסט ההתחלה של טווח הטקסט. |
end | Integer | ההיסט של סוף טווח הטקסט. |
url | String | כתובת ה-URL של הקישור. |
חזרה
Text – הרכיב הנוכחי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Link Url(url)
set Strikethrough(strikethrough)
set Strikethrough(startOffset, endOffsetInclusive, strikethrough)
הגדרת קו חוצה לטווח התווים שצוין.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Sets the first 11 characters in the tab's body to strikethrough. const text = body.editAsText().setStrikethrough(0, 10, true);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
start | Integer | היסט ההתחלה של טווח הטקסט. |
end | Integer | ההיסט של סוף טווח הטקסט. |
strikethrough | Boolean | הגדרת הקו החוצה. |
חזרה
Text – הרכיב הנוכחי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Text(text)
מגדיר את תוכן הטקסט.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Replaces the contents of the body with the text, 'New body text.' const text = body.editAsText().setText('New body text.');
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
text | String | תוכן הטקסט החדש. |
חזרה
Text – הרכיב הנוכחי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Text Alignment(startOffset, endOffsetInclusive, textAlignment)
הגדרת יישור הטקסט לטווח תווים נתון. סוגי היישור הזמינים הם Document, Document ו-Document.
// Make the first character in the first paragraph of the active tab be // superscript. const documentTab = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab(); const text = documentTab.getBody().getParagraphs()[0].editAsText(); text.setTextAlignment(0, 0, DocumentApp.TextAlignment.SUPERSCRIPT);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
start | Integer | היסט ההתחלה של טווח התווים. |
end | Integer | ההיסט של סוף טווח התווים (כולל). |
text | Text | סוג יישור הטקסט שרוצים להחיל. |
חזרה
Text – הרכיב הנוכחי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
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 | סוג יישור הטקסט שרוצים להחיל |
חזרה
Text – הרכיב הנוכחי
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Underline(underline)
set Underline(startOffset, endOffsetInclusive, underline)
הגדרת הקו התחתון לטווח התווים שצוין.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // 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(); // Sets the first 11 characters in the tab's body to underline. const text = body.editAsText().setUnderline(0, 10, true);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
start | Integer | היסט ההתחלה של טווח הטקסט. |
end | Integer | ההיסט של סוף טווח הטקסט. |
underline | Boolean | הגדרת הקו התחתון. |
חזרה
Text – הרכיב הנוכחי.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents