Class Text

טקסט

רכיב שמייצג אזור של טקסט עשיר. כל הטקסט ב-Document נמצא בתוך רכיבי Text. רכיב Text יכול להיות בתוך Equation, EquationFunction, ListItem, או Paragraph, אבל הוא לא יכול להכיל רכיב אחר בעצמו. לקבלת מידע נוסף על מבנה המסמך, אפשר לעיין במדריך להרחבת מסמכי Google Docs.

// Gets the body contents of the active tab.
var body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody();

// Use editAsText to obtain a single text element containing
// all the characters in the tab.
var 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');

שיטות

שיטהסוג הערך המוחזרתיאור קצר
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אחזור כתובת ה-URL של הקישור.
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מגדיר את כתובת האתר של הקישור עבור טווח התווים שצוין.
setLinkUrl(url)Textמגדיר את כתובת האתר של הקישור.
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/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(TAB_ID).asDocumentTab().getBody();

// Adds the text, 'Sample body text,' to the end of the tab body.
const text = body.editAsText().appendText('Sample body text');

פרמטרים

שםסוגתיאור
textStringהטקסט שצריך לצרף.

חזרה

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/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(TAB_ID).asDocumentTab().getBody();

// Deletes the first 10 characters in the body.
 const text = body.editAsText().deleteText(0, 9);

פרמטרים

שםסוגתיאור
startOffsetIntegerהיסט התווים של התו הראשון שצריך למחוק.
endOffsetInclusiveIntegerהיסט התווים של התו האחרון שצריך למחוק.

חזרה

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

אישור

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

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

editAsText()

מתקבלת גרסת Text של הרכיב הנוכחי, לעריכה.

אפשר להשתמש ב-editAsText כדי לבצע מניפולציות על התוכן של הרכיבים כטקסט עשיר. מצב editAsText מתעלם מאלמנטים שאינם טקסט (כמו InlineImage ו-HorizontalRule).

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

var 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 – גרסת טקסט של הרכיב הנוכחי


findText(searchPattern)

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

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

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

פרמטרים

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

חזרה

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

אישור

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

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

findText(searchPattern, from)

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

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

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

פרמטרים

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

חזרה

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

אישור

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

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

getAttributes()

אחזור המאפיינים של הרכיב.

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

var doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab();
var body = documentTab.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/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(TAB_ID).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);

פרמטרים

שםסוגתיאור
offsetIntegerהיסט התווים.

חזרה

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

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).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);

פרמטרים

שםסוגתיאור
offsetIntegerהיסט התווים.

חזרה

String – צבע הרקע, בפורמט של סימון CSS (כמו '#ffffff').

אישור

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

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

getFontFamily()

אחזור ההגדרה של משפחת הגופנים. השם יכול להיות כל גופן בתפריט 'גופן' ב-Docs או ב-Google Fonts, והוא תלוי אותיות רישיות. השיטות getFontFamily() ו-setFontFamily(fontFamilyName) משתמשות עכשיו בשמות מחרוזות לגופנים במקום טיפוסים בני מנייה (enum) FontFamily. למרות שה-enum הזה הוצא משימוש, הוא ימשיך להיות זמין לצורך תאימות עם סקריפטים ישנים יותר.

חזרה

String – משפחת הגופנים, או ערך null אם הרכיב מכיל כמה ערכים עבור המאפיין הזה

אישור

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

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

getFontFamily(offset)

אחזור של משפחת הגופנים בהיסט התווים שצוין. השם יכול להיות כל גופן מ תפריט הגופנים ב-Docs או ב-Google Fonts, תלוי אותיות רישיות. השיטות getFontFamily() ו-setFontFamily(fontFamilyName) השתמשו עכשיו בשמות מחרוזות לגופנים במקום ב-enum FontFamily. למרות שה-enum הזה הוצא משימוש, הוא ימשיך להיות זמין לצורך תאימות עם סקריפטים ישנים יותר.

// 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(TAB_ID).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);

פרמטרים

שםסוגתיאור
offsetIntegerהיסט התווים.

חזרה

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/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(TAB_ID).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);

פרמטרים

שםסוגתיאור
offsetIntegerהיסט התווים.

חזרה

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/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(TAB_ID).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);

פרמטרים

שםסוגתיאור
offsetIntegerהיסט התווים.

חזרה

String – צבע החזית, בפורמט CSS (כמו '#ffffff').

אישור

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

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

getLinkUrl()

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

חזרה

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

אישור

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

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

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/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(TAB_ID).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);

פרמטרים

שםסוגתיאור
offsetIntegerהיסט התווים.

חזרה

String – כתובת ה-URL של הקישור.

אישור

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

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

getNextSibling()

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

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

חזרה

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

אישור

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

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

getParent()

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

רכיב ההורה מכיל את הרכיב הנוכחי.

חזרה

ContainerElement – רכיב ההורה.

אישור

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

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

getPreviousSibling()

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

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

חזרה

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

אישור

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

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

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/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(TAB_ID).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());

פרמטרים

שםסוגתיאור
offsetIntegerההיסט של התו.

חזרה

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/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(TAB_ID).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

getType()

מאחזר את ElementType של הרכיב.

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

var doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab();
var body = documentTab.getBody();

// Obtain the first element in the active tab's 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/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(TAB_ID).asDocumentTab().getBody();

// Inserts the text, 'Sample inserted text', at the start of the body content.
const text = body.editAsText().insertText(0, 'Sample inserted text');

פרמטרים

שםסוגתיאור
offsetIntegerהיסט התווים שבו יש להוסיף את הטקסט.
textStringהטקסט להוספה.

חזרה

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

אישור

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

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

isAtDocumentEnd()

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

חזרה

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

אישור

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

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

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/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(TAB_ID).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);

פרמטרים

שםסוגתיאור
offsetIntegerהיסט התווים.

חזרה

Boolean – ההגדרה המודגשת.

אישור

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

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

isItalic()

אחזור של הגדרת ההטיה.

חזרה

Boolean - האם הטקסט נטוי, או null אם הרכיב מכיל כמה ערכים עבור המאפיין הזה שיוך

אישור

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

  • 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/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(TAB_ID).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);

פרמטרים

שםסוגתיאור
offsetIntegerהיסט התווים.

חזרה

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/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(TAB_ID).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);

פרמטרים

שםסוגתיאור
offsetIntegerהיסט התווים.

חזרה

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/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(TAB_ID).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);

פרמטרים

שםסוגתיאור
offsetIntegerהיסט התווים.

חזרה

Boolean – הגדרת הקו התחתון.

אישור

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

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

merge()

התכונה ממזגת את הרכיב עם האח הקודם מאותו סוג.

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

הרכיב הנוכחי יוסר מהמסמך.

var doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab();
var body = documentTab.getBody();

// Example 1: Merge paragraphs
// Append two paragraphs to the document's active tab.
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 doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab()
var body = documentTab.getBody();

// Remove all images in the active tab's 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. לכן, צריך לסמן בתו בריחה (escape) את כל לוכסן הפוך בתבנית.

בשיטה הזאת נעשה שימוש במודל RE2 הרגיל של Google של ביטויים, שמגבילה את התחביר הנתמך.

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

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

// Clear the text surrounding "Apps Script", with or without text.
body.replaceText("^.*Apps ?Script.*$", "Apps Script");

פרמטרים

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

חזרה

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

אישור

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

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

setAttributes(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/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(TAB_ID).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);

פרמטרים

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

חזרה

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

אישור

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

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

setAttributes(attributes)

מגדיר את המאפיינים של הרכיב.

פרמטר המאפיינים שצוין חייב להיות אובייקט שבו כל שם מאפיין הוא פריט ב- הספירה של DocumentApp.Attribute וכל ערך מאפיין הוא הערך החדש שצריך הוחלו.

var doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab();
var body = documentTab.getBody();

// Define a custom paragraph style.
var style = {};
style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] =
    DocumentApp.HorizontalAlignment.RIGHT;
style[DocumentApp.Attribute.FONT_FAMILY] = 'Calibri';
style[DocumentApp.Attribute.FONT_SIZE] = 18;
style[DocumentApp.Attribute.BOLD] = true;

// Append a plain paragraph.
var par = body.appendParagraph('A paragraph with custom style.');

// Apply the custom style.
par.setAttributes(style);

פרמטרים

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

חזרה

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/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(TAB_ID).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');

פרמטרים

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

חזרה

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

אישור

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

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

setBackgroundColor(color)

הגדרת צבע הרקע.

פרמטרים

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

חזרה

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

אישור

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

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

setBold(bold)

קביעת הגדרת הטקסט המודגש.

פרמטרים

שםסוגתיאור
boldBooleanההגדרה המודגשת

חזרה

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

אישור

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

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

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/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(TAB_ID).asDocumentTab().getBody();

// Sets the first 11 characters in the tab's body to bold.
const text = body.editAsText().setBold(0, 10, true);

פרמטרים

שםסוגתיאור
startOffsetIntegerהיסט ההתחלה של טווח הטקסט.
endOffsetInclusiveIntegerהיסט הסיום של טווח הטקסט.
boldBooleanההגדרה המודגשת.

חזרה

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

אישור

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

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

setFontFamily(startOffset, endOffsetInclusive, fontFamilyName)

מגדירה את משפחת הגופנים לטווח התווים שצוין. השם יכול להיות כל גופן מהגופן ב-Docs או ב-Google Fonts, והוא תלוי אותיות רישיות. שמות גופנים בלתי מזוהים יוצגו כ-Bard. השיטות getFontFamily(offset) ו- הפונקציה setFontFamily(fontFamilyName) משתמשת עכשיו בשמות של מחרוזות לגופנים במקום בטיפוס FontFamily enum. למרות שה-enum הזה הוצא משימוש, הוא ימשיך להיות זמין לצורך תאימות עם סקריפטים ישנים יותר.

// 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(TAB_ID).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');

פרמטרים

שםסוגתיאור
startOffsetIntegerהיסט ההתחלה של טווח הטקסט.
endOffsetInclusiveIntegerהיסט הסיום של טווח הטקסט.
fontFamilyNameStringהשם של משפחת הגופנים, מתפריט 'גופן' ב-Docs או ב-Google Fonts.

חזרה

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

אישור

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

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

setFontFamily(fontFamilyName)

מגדיר את משפחת הגופנים. השם יכול להיות כל גופן בתפריט 'גופן' ב-Docs או ב-Google Fonts, והוא תלוי אותיות רישיות. גופן לא מזוהה השמות יוצגו כ-Hello. השיטות getFontFamily() ו-setFontFamily(fontFamilyName) משתמשות עכשיו בשמות מחרוזות לגופנים במקום ב-enum FontFamily. למרות שה-enum הזה הוצא משימוש, הוא ימשיך להיות זמין לצורך תאימות עם סקריפטים ישנים יותר.

פרמטרים

שםסוגתיאור
fontFamilyNameStringשם של משפחת הגופנים, מתפריט 'גופן' ב-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/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(TAB_ID).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);

פרמטרים

שםסוגתיאור
startOffsetIntegerהיסט ההתחלה של טווח הטקסט.
endOffsetInclusiveIntegerהיסט הסיום של טווח הטקסט.
sizeNumberגודל הגופן.

חזרה

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

אישור

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

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

setFontSize(size)

מגדיר את גודל הגופן.

פרמטרים

שםסוגתיאור
sizeNumberגודל הגופן

חזרה

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

אישור

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

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

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/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(TAB_ID).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);

פרמטרים

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

חזרה

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

אישור

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

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

setForegroundColor(color)

הגדרת צבע החזית.

פרמטרים

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

חזרה

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

אישור

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

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

setItalic(italic)

מגדיר את הגדרת הגופן הנטוי.

פרמטרים

שםסוגתיאור
italicBooleanהגדרה נטויה

חזרה

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

אישור

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

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

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/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(TAB_ID).asDocumentTab().getBody();

// Sets the first 11 characters in the tab's body to italic.
const text = body.editAsText().setItalic(0, 10, true);

פרמטרים

שםסוגתיאור
startOffsetIntegerהיסט ההתחלה של טווח הטקסט.
endOffsetInclusiveIntegerהיסט הסיום של טווח הטקסט.
italicBooleanהגדרה נטויה.

חזרה

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

אישור

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

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

setLinkUrl(startOffset, endOffsetInclusive, 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(TAB_ID).asDocumentTab().getBody();

// Applies a link to the first 11 characters in the body.
const text = body.editAsText().setLinkUrl(0, 10, 'https://example.com');

פרמטרים

שםסוגתיאור
startOffsetIntegerהיסט ההתחלה של טווח הטקסט.
endOffsetInclusiveIntegerהיסט הסיום של טווח הטקסט.
urlStringכתובת ה-URL של הקישור.

חזרה

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

אישור

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

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

setLinkUrl(url)

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

פרמטרים

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

חזרה

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

אישור

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

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

setStrikethrough(strikethrough)

קביעת ההגדרה של קו חוצה.

פרמטרים

שםסוגתיאור
strikethroughBooleanהגדרת קו חוצה

חזרה

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

אישור

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

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

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/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(TAB_ID).asDocumentTab().getBody();

// Sets the first 11 characters in the tab's body to strikethrough.
const text = body.editAsText().setStrikethrough(0, 10, true);

פרמטרים

שםסוגתיאור
startOffsetIntegerהיסט ההתחלה של טווח הטקסט.
endOffsetInclusiveIntegerהיסט הסיום של טווח הטקסט.
strikethroughBooleanהגדרת קו חוצה.

חזרה

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/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(TAB_ID).asDocumentTab().getBody();

// Replaces the contents of the body with the text, 'New body text.'
const text = body.editAsText().setText('New body text.');

פרמטרים

שםסוגתיאור
textStringתוכן הטקסט החדש.

חזרה

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 of the active tab be superscript.
var documentTab = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab();
var text = documentTab.getBody().getParagraphs()[0].editAsText();
text.setTextAlignment(0, 0, DocumentApp.TextAlignment.SUPERSCRIPT);

פרמטרים

שםסוגתיאור
startOffsetIntegerהיסט ההתחלה של טווח התווים.
endOffsetInclusiveIntegerהיסט הסיום של טווח התווים (כולל).
textAlignmentTextAlignmentסוג יישור הטקסט שצריך להחיל.

חזרה

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 in the active tab be superscript.
var documentTab = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab();
var text = documentTab.getBody().getParagraphs()[0].editAsText();
text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);

פרמטרים

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

חזרה

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

אישור

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

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

setUnderline(underline)

קביעת ההגדרה של קו תחתון.

פרמטרים

שםסוגתיאור
underlineBooleanהגדרת הקו התחתון

חזרה

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

אישור

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

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

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/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(TAB_ID).asDocumentTab().getBody();

// Sets the first 11 characters in the tab's body to underline.
const text = body.editAsText().setUnderline(0, 10, true);

פרמטרים

שםסוגתיאור
startOffsetIntegerהיסט ההתחלה של טווח הטקסט.
endOffsetInclusiveIntegerהיסט הסיום של טווח הטקסט.
underlineBooleanהגדרת הקו התחתון.

חזרה

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

אישור

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

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