רכיב שמייצג אזור של טקסט עשיר. כל הטקסט ב-Document
כלול ברכיבים של Text
.
רכיב Text
יכול להיכלל ברכיב Equation
, EquationFunction
, ListItem
או Paragraph
, אבל הוא לא יכול להכיל רכיבים אחרים. למידע נוסף על מבנה המסמכים, ראו מדריך להרחבת Google Docs.
var body = DocumentApp.getActiveDocument().getBody(); // Use editAsText to obtain a single text element containing // all the characters in the document. var text = body.editAsText(); // Insert text at the beginning of the document. text.insertText(0, 'Inserted text.\n'); // Insert text at the end of the document. text.appendText('\nAppended text.'); // Make the first half of the document blue. text.setForegroundColor(0, text.getText().length / 2, '#00FFFF');
שיטות
Method | סוג החזרה | תיאור קצר |
---|---|---|
appendText(text) | Text | הוספת הטקסט שצוין לסוף של אזור הטקסט הזה. |
copy() | Text | מחזירה עותק מנותק ומעמיק של הרכיב הנוכחי. |
deleteText(startOffset, endOffsetInclusive) | Text | מתבצעת מחיקה של טווח טקסט. |
editAsText() | Text | קבלת גרסה Text של הרכיב הנוכחי לצורך עריכה. |
findText(searchPattern) | RangeElement | מחפשת בתוכן של הרכיב את דפוס הטקסט שצוין באמצעות ביטויים רגולריים. |
findText(searchPattern, from) | RangeElement | מחפשת בתוכן של הרכיב את דפוס הטקסט שצוין, החל מתוצאת חיפוש נתונה. |
getAttributes() | Object | אחזור של מאפייני הרכיב. |
getAttributes(offset) | Object | אחזור של המאפיינים בקיזוז התווים שצוין. |
getBackgroundColor() | String | אחזור של הגדרת צבע הרקע. |
getBackgroundColor(offset) | String | אחזור של צבע הרקע בקיזוז התווים שצוין. |
getFontFamily() | String | אחזור של הגדרת משפחת הגופנים. |
getFontFamily(offset) | String | אחזור של משפחת הגופנים בקיזוז התווים שצוין. |
getFontSize() | Number | אחזור של הגדרת גודל הגופן. |
getFontSize(offset) | Number | אחזור של גודל הגופן בקיזוז התווים שצוין. |
getForegroundColor() | String | אחזור של הגדרת הצבע בחזית. |
getForegroundColor(offset) | String | אחזור של צבע החזית בקיזוז התווים שצוין. |
getLinkUrl() | String | אחזור של כתובת האתר של הקישור. |
getLinkUrl(offset) | String | אחזור של כתובת ה-URL של הקישור בקיזוז התווים שצוין. |
getNextSibling() | Element | אחזור של פריט האחים הבא של הרכיב. |
getParent() | ContainerElement | אחזור של רכיב ההורה של הרכיב. |
getPreviousSibling() | Element | אחזור של פריט האח הקודם של הרכיב. |
getText() | String | אחזור של תוכן הרכיב כמחרוזת טקסט. |
getTextAlignment() | TextAlignment | מתקבלת יישור טקסט. |
getTextAlignment(offset) | TextAlignment | קבלת היישור של טקסט עבור תו אחד. |
getTextAttributeIndices() | Integer[] | אחזור של קבוצת האינדקסים של טקסט שתואמת לתחילת העיצוב של טקסט ייחודי. |
getType() | ElementType | מאחזר את ElementType של הרכיב. |
insertText(offset, text) | Text | הוספת הטקסט שצוין בקיזוז התווים שצוין. |
isAtDocumentEnd() | Boolean | קובע אם הרכיב נמצא בסוף ה-Document . |
isBold() | Boolean | אחזור של ההגדרה המודגשת. |
isBold(offset) | Boolean | אחזור של ההגדרה המודגשת בקיזוז התווים שצוין. |
isItalic() | Boolean | אחזור של ההגדרה הנטויה. |
isItalic(offset) | Boolean | אחזור של ההגדרה הנטוית בקיזוז תווים שצוין. |
isStrikethrough() | Boolean | אחזור של הגדרת קו חוצה. |
isStrikethrough(offset) | Boolean | אחזור של הגדרת קו חוצה בערך הקיזוז של התו שצוין. |
isUnderline() | Boolean | אחזור של הגדרת הקו התחתון. |
isUnderline(offset) | Boolean | אחזור של הגדרת הקו התחתון בקיזוז התווים שצוין. |
merge() | Text | ממזג את הרכיב עם האח הקודם מאותו סוג. |
removeFromParent() | Text | הסרת הרכיב מההורה שלו. |
replaceText(searchPattern, replacement) | Element | החלפת כל המופעים של תבנית טקסט נתונה במחרוזת החלפה נתונה, באמצעות ביטויים רגולריים. |
setAttributes(startOffset, endOffsetInclusive, attributes) | Text | מחיל את המאפיינים שצוינו על טווח התווים הנתון. |
setAttributes(attributes) | Text | מגדיר את מאפייני הרכיב. |
setBackgroundColor(startOffset, endOffsetInclusive, color) | Text | הגדרת צבע הרקע של טווח התווים שצוין. |
setBackgroundColor(color) | Text | הגדרת צבע הרקע. |
setBold(bold) | Text | הגדרה מודגשת. |
setBold(startOffset, endOffsetInclusive, bold) | Text | הגדרה מודגשת לטווח התווים שצוין. |
setFontFamily(startOffset, endOffsetInclusive, fontFamilyName) | Text | הגדרת משפחת הגופנים לטווח התווים שצוין. |
setFontFamily(fontFamilyName) | Text | הגדרת משפחת הגופנים. |
setFontSize(startOffset, endOffsetInclusive, size) | Text | מגדיר את גודל הגופן עבור טווח התווים שצוין. |
setFontSize(size) | Text | מגדיר את גודל הגופן. |
setForegroundColor(startOffset, endOffsetInclusive, color) | Text | הגדרת צבע החזית עבור טווח התווים שצוין. |
setForegroundColor(color) | Text | הגדרת צבע החזית. |
setItalic(italic) | Text | קובע את ההגדרה של הגופן הנטוי. |
setItalic(startOffset, endOffsetInclusive, italic) | Text | מגדיר את ההגדרה הנטויה בטווח התווים שצוין. |
setLinkUrl(startOffset, endOffsetInclusive, url) | Text | הגדרת כתובת ה-URL של הקישור עבור טווח התווים שצוין. |
setLinkUrl(url) | Text | הגדרת כתובת ה-URL של הקישור. |
setStrikethrough(strikethrough) | Text | קביעת קו חוצה. |
setStrikethrough(startOffset, endOffsetInclusive, strikethrough) | Text | קביעת קו חוצה עבור טווח התווים שצוין. |
setText(text) | Text | מגדיר את תוכן הטקסט. |
setTextAlignment(startOffset, endOffsetInclusive, textAlignment) | Text | הגדרת יישור הטקסט לטווח תווים נתון. |
setTextAlignment(textAlignment) | Text | הגדרת יישור הטקסט. |
setUnderline(underline) | Text | קביעת ההגדרה של הקו התחתון. |
setUnderline(startOffset, endOffsetInclusive, underline) | Text | קובע את הגדרת הקו התחתון לטווח התווים שצוין. |
מסמכים מפורטים
appendText(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/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Adds the text, 'Sample body text,' to the end of the document 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
deleteText(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/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Deletes the first 10 characters in the body. const text = body.editAsText().deleteText(0, 9);
פרמטרים
שם | סוג | תיאור |
---|---|---|
startOffset | Integer | הסטייה של התו הראשון למחיקה. |
endOffsetInclusive | Integer | הסטייה של התו האחרון למחיקה. |
הלוך ושוב
Text
— הרכיב הנוכחי.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
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
— גרסת טקסט של הרכיב הנוכחי
findText(searchPattern)
מחפשת בתוכן של הרכיב את דפוס הטקסט שצוין באמצעות ביטויים רגולריים.
קבוצת משנה של תכונות הביטוי הרגולרי ב-JavaScript אינה נתמכת באופן מלא, כמו קבוצות צילום ושינויי מצב.
תבנית הביטוי הרגולרי שסופקה תואמת באופן בלתי תלוי לכל גוש טקסט שמכיל את הרכיב הנוכחי.
פרמטרים
שם | סוג | תיאור |
---|---|---|
searchPattern | String | את הדפוס לחיפוש |
הלוך ושוב
RangeElement
— תוצאת חיפוש שמציינת את המיקום של טקסט החיפוש, או ריק אם אין התאמה
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
findText(searchPattern, from)
מחפשת בתוכן של הרכיב את דפוס הטקסט שצוין, החל מתוצאת חיפוש נתונה.
קבוצת משנה של תכונות הביטוי הרגולרי ב-JavaScript אינה נתמכת באופן מלא, כמו קבוצות צילום ושינויי מצב.
תבנית הביטוי הרגולרי שסופקה תואמת באופן בלתי תלוי לכל גוש טקסט שמכיל את הרכיב הנוכחי.
פרמטרים
שם | סוג | תיאור |
---|---|---|
searchPattern | String | את הדפוס לחיפוש |
from | RangeElement | תוצאת החיפוש שממנה יש לחפש |
הלוך ושוב
RangeElement
— תוצאת חיפוש שמציינת את המיקום הבא בטקסט של החיפוש, או ריק אם אין
התאמה
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
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
getAttributes(offset)
אחזור של המאפיינים בקיזוז התווים שצוין.
התוצאה היא אובייקט שמכיל מאפיין לכל מאפיין טקסט חוקי, כאשר כל שם נכס תואם לפריט בספירה של DocumentApp.Attribute
.
// 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/abc123456/edit'); // Gets the document body. const body = doc.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 document 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
getBackgroundColor()
אחזור של הגדרת צבע הרקע.
הלוך ושוב
String
— צבע הרקע, בפורמט CSS (כמו '#ffffff'
) או ריק
אם הרכיב מכיל כמה ערכים למאפיין הזה
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getBackgroundColor(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/abc123456'); // Gets the document body. const body = doc.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
— צבע הרקע, בפורמט CSS (כמו '#ffffff'
).
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getFontFamily()
אחזור של הגדרת משפחת הגופנים. השם יכול להיות כל גופן מתפריט 'גופנים' ב-Docs או בגופנים של Google, והוא תלוי אותיות רישיות. השיטות getFontFamily()
ו-setFontFamily(fontFamilyName)
משתמשות עכשיו בשמות מחרוזות לגופנים במקום במספר
. למרות שהסכום הזה הוצא משימוש, הוא ימשיך להיות זמין לצורך תאימות לסקריפטים ישנים יותר.FontFamily
הלוך ושוב
String
— משפחת הגופנים, או null אם הרכיב מכיל ערכים מרובים עבור המאפיין הזה
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getFontFamily(offset)
אחזור של משפחת הגופנים בקיזוז התווים שצוין. השם יכול להיות כל גופן בתפריט 'גופנים' ב-Docs או ב-Google Fonts, והוא תלוי אותיות רישיות. השיטות getFontFamily()
ו-setFontFamily(fontFamilyName)
משתמשות עכשיו בשמות מחרוזות בגופנים במקום במספר '
'. למרות שהסכום הזה הוצא משימוש, הוא ימשיך להיות זמין לצורך תאימות לסקריפטים ישנים יותר.
FontFamily
// 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/abc123456/edit'); // Gets the document body. const body = doc.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 document body. const fontFamily = text.getFontFamily(15); // Logs the font family to the console. console.log(fontFamily);
פרמטרים
שם | סוג | תיאור |
---|---|---|
offset | Integer | הסטייה בדמות. |
הלוך ושוב
String
- משפחת הגופנים.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getFontSize()
אחזור של הגדרת גודל הגופן.
הלוך ושוב
Number
— גודל הגופן, או null אם הרכיב מכיל כמה ערכים למאפיין הזה
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getFontSize(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/abc123456/edit'); // Gets the document body. const body = doc.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
— גודל הגופן.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getForegroundColor()
אחזור של הגדרת הצבע בחזית.
הלוך ושוב
String
— הצבע בחזית, בפורמט CSS (כמו '#ffffff'
) או ריק
אם הרכיב מכיל כמה ערכים למאפיין הזה
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getForegroundColor(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/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the foreground color of the first 3 characters in the document body. const text = body.editAsText().setForegroundColor(0, 2, '#0000FF'); // Gets the foreground color of the first character in the document body. const foregroundColor = text.getForegroundColor(0); // Logs the foreground color to the console. console.log(foregroundcolor);
פרמטרים
שם | סוג | תיאור |
---|---|---|
offset | Integer | הסטייה בדמות. |
הלוך ושוב
String
— הצבע בחזית, בפורמט CSS (כמו '#ffffff'
).
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getLinkUrl()
אחזור של כתובת האתר של הקישור.
הלוך ושוב
String
— כתובת ה-URL של הקישור, או null אם הרכיב מכיל כמה ערכים למאפיין הזה
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getLinkUrl(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/abc123456/edit'); // Gets the document body. const body = doc.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
— כתובת ה-URL של הקישור.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getNextSibling()
getParent()
אחזור של רכיב ההורה של הרכיב.
רכיב ההורה מכיל את הרכיב הנוכחי.
הלוך ושוב
ContainerElement
— רכיב ההורה.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPreviousSibling()
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
getTextAlignment(offset)
קבלת היישור של טקסט עבור תו אחד. סוגי היישור הזמינים הם DocumentApp.TextAlignment.NORMAL
, DocumentApp.TextAlignment.SUBSCRIPT
ו-DocumentApp.TextAlignment.SUPERSCRIPT
.
// 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/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the text alignment of the document 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 | הסטייה של הדמות. |
הלוך ושוב
TextAlignment
— סוג יישור הטקסט, או null
אם יישור הטקסט מעולם לא הוגדר.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getTextAttributeIndices()
אחזור של קבוצת האינדקסים של טקסט שתואמת לתחילת העיצוב של טקסט ייחודי.
// 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/abc123456/edit'); // Gets the document body. const body = doc.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
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
insertText(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/abc123456/edit'); // Gets the document body. const body = doc.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
isAtDocumentEnd()
isBold()
אחזור של ההגדרה המודגשת.
הלוך ושוב
Boolean
— אם הטקסט מודגש או ריק אם הרכיב מכיל כמה ערכים עבור המאפיין
הזה
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isBold(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/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Bolds the first 4 characters in the document 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
— ההגדרה מודגשת.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isItalic()
אחזור של ההגדרה הנטויה.
הלוך ושוב
Boolean
— אם הטקסט נטוי או ריק אם הרכיב מכיל כמה ערכים עבור המאפיין
הזה
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isItalic(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/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the first 13 characters of the document body to italic. const text = body.editAsText().setItalic(0, 12, true); // Gets whether the fifth character in the document body is set to // italic and logs it to the console. const italic = text.isItalic(4); console.log(italic);
פרמטרים
שם | סוג | תיאור |
---|---|---|
offset | Integer | הסטייה בדמות. |
הלוך ושוב
Boolean
— ההגדרה הנטוית.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isStrikethrough()
אחזור של הגדרת קו חוצה.
הלוך ושוב
Boolean
— אם הטקסט מסומן בקו חוצה, או ריק אם הרכיב מכיל כמה ערכים עבור המאפיין
הזה
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isStrikethrough(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/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the first 17 characters of the document body to strikethrough. const text = body.editAsText().setStrikethrough(0, 16, true); // Gets whether the first character in the document body is set to // strikethrough and logs it to the console. const strikethrough = text.isStrikethrough(0); console.log(strikethrough);
פרמטרים
שם | סוג | תיאור |
---|---|---|
offset | Integer | הסטייה בדמות. |
הלוך ושוב
Boolean
– הגדרת קו חוצה.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isUnderline()
אחזור של הגדרת הקו התחתון.
הלוך ושוב
Boolean
— אם הטקסט מסומן בקו תחתון או ריק אם הרכיב מכיל כמה ערכים עבור המאפיין הזה
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isUnderline(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/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the first 13 characters of the document body to underline. const text = body.editAsText().setUnderline(0, 12, false); // Gets whether the first character in the document body is set to // underline and logs it to the console const underline = text.editAsText().isUnderline(0); console.log(underline);
פרמטרים
שם | סוג | תיאור |
---|---|---|
offset | Integer | הסטייה בדמות. |
הלוך ושוב
Boolean
– הגדרת הקו התחתון.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
merge()
ממזג את הרכיב עם האח הקודם מאותו סוג.
ניתן למזג רק רכיבים של אותו ElementType
. כל רכיבי הצאצא שנכללים ברכיב הנוכחי מועברים לאלמנט האח הקודם.
הרכיב הנוכחי יוסר מהמסמך.
var body = DocumentApp.getActiveDocument().getBody(); // Example 1: Merge paragraphs // Append two paragraphs to the document. var par1 = body.appendParagraph('Paragraph 1.'); var 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. var cells = [ ['Row 1, Cell 1', 'Row 1, Cell 2'], ['Row 2, Cell 1', 'Row 2, Cell 2'] ]; // Build a table from the array. var table = body.appendTable(cells); // Get the first row in the table. var row = table.getRow(0); // Get the two cells in this row. var cell1 = row.getCell(0); var cell2 = row.getCell(1); // Merge the current cell into its preceding sibling element. var merged = cell2.merge();
הלוך ושוב
Text
— הרכיב שמוזג.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
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(); }
הלוך ושוב
Text
— הרכיב שהוסר.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
replaceText(searchPattern, replacement)
החלפת כל המופעים של תבנית טקסט נתונה במחרוזת החלפה נתונה, באמצעות ביטויים רגולריים.
דפוס החיפוש מועבר כמחרוזת, ולא כאובייקט ביטוי רגולרי של JavaScript. מסיבה זו עליך לסמן קו נטוי לאחור בקו ביטול הנעילה.
השיטה הזו משתמשת בספריית הביטוי הרגולרי 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(startOffset, endOffsetInclusive, attributes)
מחיל את המאפיינים שצוינו על טווח התווים הנתון.
הפרמטר 'מאפיינים' שצוין צריך להיות אובייקט, כאשר כל שם נכס הוא פריט בספירה של DocumentApp.Attribute
וכל ערך של מאפיין הוא הערך החדש שרוצים להחיל.
// 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/abc123456/edit'); // Gets the document body and edits as text. const body = doc.getBody().editAsText(); // 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 document body. const text = body.setAttributes(0, 8, style);
פרמטרים
שם | סוג | תיאור |
---|---|---|
startOffset | Integer | טווח ההתחלה של טווח הטקסט. |
endOffsetInclusive | Integer | טווח הסיום של טווח הטקסט. |
attributes | Object | המאפיינים של הרכיב. |
הלוך ושוב
Text
— הרכיב הנוכחי.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
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 | המאפיינים של הרכיב. |
הלוך ושוב
Text
— הרכיב הנוכחי.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setBackgroundColor(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/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the background color of the first 3 characters in the // document body to hex color #0000FF. const text = body.editAsText().setBackgroundColor(0, 2, '#0000FF');
פרמטרים
שם | סוג | תיאור |
---|---|---|
startOffset | Integer | טווח ההתחלה של טווח הטקסט. |
endOffsetInclusive | Integer | טווח הסיום של טווח הטקסט. |
color | String | צבע הרקע, בפורמט CSS (כמו '#ffffff' ). |
הלוך ושוב
Text
— הרכיב הנוכחי.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setBackgroundColor(color)
setBold(bold)
setBold(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/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the first 11 characters in the document body to bold. const text = body.editAsText().setBold(0, 10, true);
פרמטרים
שם | סוג | תיאור |
---|---|---|
startOffset | Integer | טווח ההתחלה של טווח הטקסט. |
endOffsetInclusive | Integer | טווח הסיום של טווח הטקסט. |
bold | Boolean | הגדרה מודגשת. |
הלוך ושוב
Text
— הרכיב הנוכחי.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setFontFamily(startOffset, endOffsetInclusive, fontFamilyName)
הגדרת משפחת הגופנים לטווח התווים שצוין. השם יכול להיות כל גופן בתפריט 'גופנים' ב-Docs או ב-Google Fonts, והוא תלוי אותיות רישיות.
שמות לא מזוהים של גופנים יוצגו כ-Id. השיטות getFontFamily(offset)
ו-setFontFamily(fontFamilyName)
משתמשות עכשיו בשמות מחרוזות לגופנים במקום במספר
. למרות שהסכום הזה הוצא משימוש, הוא ימשיך להיות זמין לצורך תאימות לסקריפטים ישנים יותר.
FontFamily
// 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/abc123456/edit'); // Gets body of the document. const body = doc.getBody(); // Sets the font of the first 4 characters in the document body to Roboto. const text = body.editAsText().setFontFamily(0, 3, 'Roboto');
פרמטרים
שם | סוג | תיאור |
---|---|---|
startOffset | Integer | טווח ההתחלה של טווח הטקסט. |
endOffsetInclusive | Integer | טווח הסיום של טווח הטקסט. |
fontFamilyName | String | השם של משפחת הגופנים, מתפריט 'גופנים' ב-Docs או ב-Google Fonts. |
הלוך ושוב
Text
— הרכיב הנוכחי.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setFontFamily(fontFamilyName)
הגדרת משפחת הגופנים. השם יכול להיות כל גופן מתפריט 'גופנים' ב-Docs או בגופנים של Google, והוא תלוי אותיות רישיות. שמות לא מזוהים של גופנים יוצגו כ-Id. השיטות getFontFamily()
ו-setFontFamily(fontFamilyName)
משתמשות עכשיו בשמות מחרוזות לגופנים במקום במספר
. למרות שהסכום הזה הוצא משימוש, הוא ימשיך להיות זמין לצורך תאימות לסקריפטים ישנים יותר.FontFamily
פרמטרים
שם | סוג | תיאור |
---|---|---|
fontFamilyName | String | השם של משפחת הגופנים, מתפריט 'גופנים' ב-Docs או ב-Google Fonts |
הלוך ושוב
Text
— הרכיב הנוכחי
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setFontSize(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/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the size of the first 11 characters in the document body to 12. const text = body.editAsText().setFontSize(0, 10, 12);
פרמטרים
שם | סוג | תיאור |
---|---|---|
startOffset | Integer | טווח ההתחלה של טווח הטקסט. |
endOffsetInclusive | Integer | טווח הסיום של טווח הטקסט. |
size | Number | גודל הגופן. |
הלוך ושוב
Text
— הרכיב הנוכחי.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setFontSize(size)
setForegroundColor(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/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the foreground color of the first 2 characters in the // document body to hex color #FF0000. const text = body.editAsText().setForegroundColor(0, 1, '#FF0000'); // Gets the foreground color for the second character in the document body. const foregroundColor = text.getForegroundColor(1); // Logs the foreground color to the console. console.log(foregroundColor);
פרמטרים
שם | סוג | תיאור |
---|---|---|
startOffset | Integer | טווח ההתחלה של טווח הטקסט. |
endOffsetInclusive | Integer | טווח הסיום של טווח הטקסט. |
color | String | צבע החזית, בפורמט CSS (כמו '#ffffff' ). |
הלוך ושוב
Text
— הרכיב הנוכחי.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setForegroundColor(color)
setItalic(italic)
setItalic(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/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the first 11 characters in the document body to italic. const text = body.editAsText().setItalic(0, 10, true);
פרמטרים
שם | סוג | תיאור |
---|---|---|
startOffset | Integer | טווח ההתחלה של טווח הטקסט. |
endOffsetInclusive | Integer | טווח הסיום של טווח הטקסט. |
italic | Boolean | הגדרה של גופן נטוי. |
הלוך ושוב
Text
— הרכיב הנוכחי.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setLinkUrl(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/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Applies a link to the first 11 characters in the body. const text = body.editAsText().setLinkUrl(0, 10, 'https://example.com');
פרמטרים
שם | סוג | תיאור |
---|---|---|
startOffset | Integer | טווח ההתחלה של טווח הטקסט. |
endOffsetInclusive | Integer | טווח הסיום של טווח הטקסט. |
url | String | כתובת ה-URL של הקישור. |
הלוך ושוב
Text
— הרכיב הנוכחי.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setLinkUrl(url)
setStrikethrough(strikethrough)
setStrikethrough(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/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the first 11 characters in the document body to strikethrough. const text = body.editAsText().setStrikethrough(0, 10, true);
פרמטרים
שם | סוג | תיאור |
---|---|---|
startOffset | Integer | טווח ההתחלה של טווח הטקסט. |
endOffsetInclusive | Integer | טווח הסיום של טווח הטקסט. |
strikethrough | Boolean | הגדרת קו חוצה. |
הלוך ושוב
Text
— הרכיב הנוכחי.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setText(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/abc123456/edit'); // Gets the document body. const body = doc.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
setTextAlignment(startOffset, endOffsetInclusive, textAlignment)
הגדרת יישור הטקסט לטווח תווים נתון. סוגי היישור הזמינים הם DocumentApp.TextAlignment.NORMAL
, DocumentApp.TextAlignment.SUBSCRIPT
ו-DocumentApp.TextAlignment.SUPERSCRIPT
.
// Make the first character in the first paragraph be superscript. var text = DocumentApp.getActiveDocument().getBody().getParagraphs()[0].editAsText(); text.setTextAlignment(0, 0, DocumentApp.TextAlignment.SUPERSCRIPT);
פרמטרים
שם | סוג | תיאור |
---|---|---|
startOffset | Integer | היסט ההתחלה של טווח התווים. |
endOffsetInclusive | Integer | היסט הסיום של טווח התווים (כולל). |
textAlignment | TextAlignment | סוג יישור הטקסט שרוצים להחיל. |
הלוך ושוב
Text
— הרכיב הנוכחי.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
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);
פרמטרים
שם | סוג | תיאור |
---|---|---|
textAlignment | TextAlignment | סוג יישור הטקסט שיש להחיל |
הלוך ושוב
Text
— הרכיב הנוכחי
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setUnderline(underline)
setUnderline(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/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the first 11 characters in the document body to underline. const text = body.editAsText().setUnderline(0, 10, true);
פרמטרים
שם | סוג | תיאור |
---|---|---|
startOffset | Integer | טווח ההתחלה של טווח הטקסט. |
endOffsetInclusive | Integer | טווח הסיום של טווח הטקסט. |
underline | Boolean | הגדרת הקו התחתון. |
הלוך ושוב
Text
— הרכיב הנוכחי.
הרשאה
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה באמצעות אחד או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents