Class Text

טקסט

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

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

// Use editAsText to obtain a single text element containing
// all the characters in the tab.
const text = body.editAsText();

// Insert text at the beginning of the tab.
text.insertText(0, 'Inserted text.\n');

// Insert text at the end of the tab.
text.appendText('\nAppended text.');

// Make the first half of the tab blue.
text.setForegroundColor(0, text.getText().length / 2, '#00FFFF');

Methods

שיטהסוג הערך שמוחזרתיאור קצר
appendText(text)Textהוספת הטקסט שצוין לסוף אזור הטקסט הזה.
copy()Textמחזירה עותק מנותק ועמוק של הרכיב הנוכחי.
deleteText(startOffset, endOffsetInclusive)Textמחיקת טווח של טקסט.
editAsText()Textמקבלים גרסה Text של הרכיב הנוכחי לצורך עריכה.
findText(searchPattern)RangeElement|nullמחפשת בתוכן של הרכיב את תבנית הטקסט שצוינה באמצעות ביטויים רגולריים.
findText(searchPattern, from)RangeElement|nullמחפש בתוכן של הרכיב את תבנית הטקסט שצוינה, החל מתוצאת חיפוש נתונה.
getAttributes()Objectמאחזר את המאפיינים של האלמנט.
getAttributes(offset)Objectהפונקציה מאחזרת את המאפיינים בהיסט התווים שצוין.
getBackgroundColor()String|nullמאחזר את הגדרת צבע הרקע.
getBackgroundColor(offset)String|nullמאחזרת את צבע הרקע בהיסט התווים שצוין.
getFontFamily()String|nullמאחזר את ההגדרה של משפחת הגופנים.
getFontFamily(offset)String|nullהפונקציה מאחזרת את משפחת הגופנים בהיסט התווים שצוין.
getFontSize()Number|nullמאחזר את ההגדרה של גודל הגופן.
getFontSize(offset)Number|nullהפונקציה מאחזרת את גודל הגופן בהיסט התווים שצוין.
getForegroundColor()String|nullמאחזר את הגדרת צבע החזית.
getForegroundColor(offset)String|nullהפונקציה מאחזרת את צבע החזית במיקום התו שצוין.
getLinkUrl()String|nullהפונקציה מחזירה את כתובת ה-URL של הקישור.
getLinkUrl(offset)String|nullהפונקציה מאחזרת את כתובת ה-URL של הקישור בהיסט התווים שצוין.
getNextSibling()Element|nullמחזירה את רכיב האח הבא של הרכיב.
getParent()ContainerElement|nullמאחזר את אלמנט ההורה של האלמנט.
getPreviousSibling()Element|nullמאחזר את רכיב האח הקודם של הרכיב.
getText()Stringמאחזרת את התוכן של הרכיב כמחרוזת טקסט.
getTextAlignment()TextAlignment|nullמקבל את יישור הטקסט.
getTextAlignment(offset)TextAlignment|nullמקבלת את יישור הטקסט של תו יחיד.
getTextAttributeIndices()Integer[]מאחזר את קבוצת אינדקסים של טקסט שתואמים להתחלה של רצפים נפרדים של עיצוב טקסט.
getType()ElementTypeאחזור ElementType של הרכיב.
insertText(offset, text)Textהפונקציה מוסיפה את הטקסט שצוין בהיסט התווים שצוין.
isAtDocumentEnd()Booleanההגדרה קובעת אם הרכיב נמצא בסוף Document.
isBold()Boolean|nullמאחזר את ההגדרה של הטקסט המודגש.
isBold(offset)Boolean|nullאחזור הגדרת ההדגשה בהיסט התווים שצוין.
isItalic()Boolean|nullמאחזר את ההגדרה של הטקסט המוטה.
isItalic(offset)Boolean|nullאחזור ההגדרה של הטיית הטקסט במיקום התו שצוין.
isStrikethrough()Boolean|nullמאחזר את הגדרת הקו החוצה.
isStrikethrough(offset)Boolean|nullהפונקציה מאחזרת את הגדרת הקו החוצה במיקום התו שצוין.
isUnderline()Boolean|nullמאחזר את הגדרת הקו התחתון.
isUnderline(offset)Boolean|nullהפונקציה מאחזרת את הגדרת הקו התחתון במיקום התו שצוין.
merge()Text|nullמיזוג הרכיב עם הרכיב הקודם מאותו סוג.
removeFromParent()Text|nullהפונקציה מסירה את הרכיב מהרכיב ההורה שלו.
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/DOCUMENT_ID/edit',
);

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab('123abc').asDocumentTab().getBody();

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

פרמטרים

שםסוגתיאור
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('123abc').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).

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

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

// Insert two paragraphs separated by a paragraph containing an
// horizontal rule.
body.insertParagraph(0, 'An editAsText sample.');
body.insertHorizontalRule(0);
body.insertParagraph(0, 'An example.');

// Delete " sample.\n\n An" removing the horizontal rule in the process.
body.editAsText().deleteText(14, 25);

חזרה

Text – גרסת טקסט של הרכיב הנוכחי


findText(searchPattern)

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

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

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

פרמטרים

שםסוגתיאור
searchPatternStringהתבנית לחיפוש

חזרה

RangeElement|null – תוצאת חיפוש שמציינת את המיקום של טקסט החיפוש, או null אם אין התאמה

אישור

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

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

findText(searchPattern, from)

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

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

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

פרמטרים

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

חזרה

RangeElement|null — תוצאת חיפוש שמציינת את המיקום הבא של טקסט החיפוש, או null אם אין התאמה

אישור

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

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

getAttributes()

מאחזר את המאפיינים של האלמנט.

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

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

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

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

// Log the paragraph attributes.
for (const att in atts) {
  Logger.log(`${att}:${atts[att]}`);
}

חזרה

Object – מאפייני הרכיב.

אישור

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

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

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('123abc').asDocumentTab().getBody();

// Declares style attributes.
const style = {};
style[DocumentApp.Attribute.BOLD] = true;
style[DocumentApp.Attribute.ITALIC] = true;
style[DocumentApp.Attribute.FONT_SIZE] = 29;

// Sets the style attributes to the tab's body.
const text = body.editAsText();
text.setAttributes(style);

// Gets the style attributes applied to the eleventh character in the
// body and logs them to the console.
const attributes = text.getAttributes(10);
console.log(attributes);

פרמטרים

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

חזרה

Object – מאפייני הרכיב.

אישור

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

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

getBackgroundColor()

מאחזר את הגדרת צבע הרקע.

חזרה

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

אישור

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

  • 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('123abc').asDocumentTab().getBody();

// Sets the background color of the first 3 characters in the body.
const text = body.editAsText().setBackgroundColor(0, 2, '#FFC0CB');

// Gets the background color of the first character in the body.
const backgroundColor = text.getBackgroundColor(0);

// Logs the background color to the console.
console.log(backgroundColor);

פרמטרים

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

חזרה

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

אישור

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

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

getFontFamily()

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

חזרה

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

אישור

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

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

getFontFamily(offset)

הפונקציה מאחזרת את משפחת הגופנים בהיסט התווים שצוין. השם יכול להיות כל גופן מהתפריט Font ב-Docs או מ-Google Fonts, והוא תלוי באותיות רישיות. השיטות getFontFamily() ו-setFontFamily(fontFamilyName) משתמשות עכשיו בשמות מחרוזות לגופנים במקום ב-enum‏ 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/DOCUMENT_ID/edit',
);

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab('123abc').asDocumentTab().getBody();

// Sets the font of the first 16 characters to Impact.
const text = body.editAsText().setFontFamily(0, 15, 'Impact');

// Gets the font family of the 16th character in the tab body.
const fontFamily = text.getFontFamily(15);

// Logs the font family to the console.
console.log(fontFamily);

פרמטרים

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

חזרה

String|null — משפחת הגופנים.

אישור

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

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

getFontSize()

מאחזר את ההגדרה של גודל הגופן.

חזרה

Number|null – גודל הגופן, או 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('123abc').asDocumentTab().getBody();

// Sets the font size of the first 13 characters to 15.
const text = body.editAsText().setFontSize(0, 12, 15);

// Gets the font size of the first character.
const fontSize = text.getFontSize(0);

// Logs the font size to the console.
console.log(fontSize);

פרמטרים

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

חזרה

Number|null — גודל הגופן.

אישור

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

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

getForegroundColor()

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

חזרה

String|null – צבע החזית, בפורמט של סימון CSS (לדוגמה, '#ffffff'), או null אם הרכיב מכיל כמה ערכים למאפיין הזה

אישור

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

  • 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('123abc').asDocumentTab().getBody();

// Sets the foreground color of the first 3 characters in the tab body.
const text = body.editAsText().setForegroundColor(0, 2, '#0000FF');

// Gets the foreground color of the first character in the tab body.
const foregroundColor = text.getForegroundColor(0);

// Logs the foreground color to the console.
console.log(foregroundColor);

פרמטרים

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

חזרה

String|null – צבע החזית, בפורמט של סימון CSS (למשל '#ffffff').

אישור

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

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

getLinkUrl()

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

חזרה

String|null – כתובת ה-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('123abc').asDocumentTab().getBody();

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

// Gets the URL of the link from the first character.
const link = text.getLinkUrl(0);

// Logs the link URL to the console.
console.log(link);

פרמטרים

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

חזרה

String|null — כתובת ה-URL של הקישור.

אישור

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

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

getNextSibling()

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

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

חזרה

Element|null – הרכיב הבא באותה רמה.

אישור

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

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

getParent()

מאחזר את אלמנט ההורה של האלמנט.

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

חזרה

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

אישור

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

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

getPreviousSibling()

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

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

חזרה

Element|null – רכיב האח הקודם.

אישור

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

  • 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 – סוג יישור הטקסט, או 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('123abc').asDocumentTab().getBody();

// Sets the text alignment of the tab's body to NORMAL.
const text =
    body.editAsText().setTextAlignment(DocumentApp.TextAlignment.NORMAL);

// Gets the text alignment of the ninth character.
const alignment = text.getTextAlignment(8);

// Logs the text alignment to the console.
console.log(alignment.toString());

פרמטרים

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

חזרה

TextAlignment|null – סוג יישור הטקסט, או 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('123abc').asDocumentTab().getBody();

// Gets the text indices at which text formatting changes.
const indices = body.editAsText().getTextAttributeIndices();

// Logs the indices to the console.
console.log(indices.toString());

חזרה

Integer[] — קבוצת האינדקסים של הטקסט שבהם משתנה עיצוב הטקסט.

אישור

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

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

getType()

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

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

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

// Obtain the first element in the active tab's body.

const firstChild = body.getChild(0);

// Use getType() to determine the element's type.
if (firstChild.getType() === DocumentApp.ElementType.PARAGRAPH) {
  Logger.log('The first element is a paragraph.');
} else {
  Logger.log('The first element is not a paragraph.');
}

חזרה

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('123abc').asDocumentTab().getBody();

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

פרמטרים

שםסוגתיאור
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|null – האם הטקסט מודגש, או null אם הרכיב מכיל כמה ערכים למאפיין הזה

אישור

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

  • 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('123abc').asDocumentTab().getBody();

// Bolds the first 4 characters in the tab body.
const text = body.editAsText().setBold(0, 3, true);

// Gets whether or not the text is bold.
const bold = text.editAsText().isBold(0);

// Logs the text's bold setting to the console
console.log(bold);

פרמטרים

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

חזרה

Boolean|null — ההגדרה להדגשה.

אישור

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

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

isItalic()

מאחזר את ההגדרה של הטקסט הנטוי.

חזרה

Boolean|null – האם הטקסט מוטה, או 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('123abc').asDocumentTab().getBody();

// Sets the first 13 characters of the tab body to italic.
const text = body.editAsText().setItalic(0, 12, true);

// Gets whether the fifth character in the tab body is set to
// italic and logs it to the console.
const italic = text.isItalic(4);
console.log(italic);

פרמטרים

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

חזרה

Boolean|null — ההגדרה של הטקסט הנטוי.

אישור

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

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

isStrikethrough()

מאחזר את הגדרת הקו החוצה.

חזרה

Boolean|null – האם הטקסט הוא קו חוצה, או null אם הרכיב מכיל כמה ערכים של המאפיין הזה

אישור

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

  • 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('123abc').asDocumentTab().getBody();

// Sets the first 17 characters of the tab body to strikethrough.
const text = body.editAsText().setStrikethrough(0, 16, true);

// Gets whether the first character in the tab body is set to
// strikethrough and logs it to the console.
const strikethrough = text.isStrikethrough(0);
console.log(strikethrough);

פרמטרים

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

חזרה

Boolean|null — הגדרת הקו החוצה.

אישור

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

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

isUnderline()

מאחזר את הגדרת הקו התחתון.

חזרה

Boolean|null – אם הטקסט מודגש או הערך null אם הרכיב מכיל כמה ערכים של המאפיין הזה

אישור

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

  • 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('123abc').asDocumentTab().getBody();

// Sets the first 13 characters of the tab body to underline.
const text = body.editAsText().setUnderline(0, 12, false);

// Gets whether the first character in the tab body is set to
// underline and logs it to the console
const underline = text.editAsText().isUnderline(0);
console.log(underline);

פרמטרים

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

חזרה

Boolean|null — הגדרת הקו התחתון.

אישור

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

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

merge()

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

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

האלמנט הנוכחי יוסר מהמסמך.

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

// Example 1: Merge paragraphs
// Append two paragraphs to the document's active tab.
const par1 = body.appendParagraph('Paragraph 1.');
const par2 = body.appendParagraph('Paragraph 2.');
// Merge the newly added paragraphs into a single paragraph.
par2.merge();

// Example 2: Merge table cells
// Create a two-dimensional array containing the table's cell contents.
const cells = [
  ['Row 1, Cell 1', 'Row 1, Cell 2'],
  ['Row 2, Cell 1', 'Row 2, Cell 2'],
];
// Build a table from the array.
const table = body.appendTable(cells);
// Get the first row in the table.
const row = table.getRow(0);
// Get the two cells in this row.
const cell1 = row.getCell(0);
const cell2 = row.getCell(1);
// Merge the current cell into its preceding sibling element.
const merged = cell2.merge();

חזרה

Text|null – הרכיב הממוזג.

אישור

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

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

removeFromParent()

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

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

// Remove all images in the active tab's body.
const imgs = body.getImages();
for (let i = 0; i < imgs.length; i++) {
  imgs[i].removeFromParent();
}

חזרה

Text|null — הרכיב שהוסר.

אישור

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

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

replaceText(searchPattern, replacement)

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

תבנית החיפוש מועברת כמחרוזת, ולא כאובייקט ביטוי רגולרי של JavaScript. לכן, צריך להשתמש בתו בריחה (escape) לכל קו נטוי הפוך בתבנית.

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

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

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

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

פרמטרים

שםסוגתיאור
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('123abc').asDocumentTab().getBody();

// Declares style attributes for font size and font family.
const style = {};
style[DocumentApp.Attribute.FONT_SIZE] = 20;
style[DocumentApp.Attribute.FONT_FAMILY] = 'Impact';

// Sets the style attributes to the first 9 characters in the tab's body.
const text = body.setAttributes(0, 8, style);

פרמטרים

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

חזרה

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

אישור

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

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

setAttributes(attributes)

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

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

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

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

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

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

פרמטרים

שםסוגתיאור
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('123abc').asDocumentTab().getBody();

// Sets the background color of the first 3 characters in the
// tab body to hex color #0000FF.
const text = body.editAsText().setBackgroundColor(0, 2, '#0000FF');

פרמטרים

שםסוגתיאור
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('123abc').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)

הגדרת משפחת הגופנים לטווח התווים שצוין. השם יכול להיות כל גופן מהתפריט Font (גופן) ב-Docs או מ-Google Fonts, והוא תלוי אותיות רישיות. שמות גופנים לא מזוהים יוצגו כ-Arial. השיטות getFontFamily(offset) ו-setFontFamily(fontFamilyName) משתמשות עכשיו בשמות מחרוזות לגופנים במקום ב-enum‏ 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/DOCUMENT_ID/edit',
);

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab('123abc').asDocumentTab().getBody();

// Sets the font of the first 4 characters in the tab's body to Roboto.
const text = body.editAsText().setFontFamily(0, 3, 'Roboto');

פרמטרים

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

חזרה

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

אישור

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

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

setFontFamily(fontFamilyName)

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

פרמטרים

שםסוגתיאור
fontFamilyNameStringהשם של משפחת הגופנים, מתוך תפריט הגופנים ב-Docs או בגופנים של Google

חזרה

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('123abc').asDocumentTab().getBody();

// Sets the size of the first 11 characters in the tab's body to 12.
const text = body.editAsText().setFontSize(0, 10, 12);

פרמטרים

שםסוגתיאור
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('123abc').asDocumentTab().getBody();

// Sets the foreground color of the first 2 characters in the
// tab's body to hex color #FF0000.
const text = body.editAsText().setForegroundColor(0, 1, '#FF0000');

// Gets the foreground color for the second character in the tab's body.
const foregroundColor = text.getForegroundColor(1);

//  Logs the foreground color to the console.
console.log(foregroundColor);

פרמטרים

שםסוגתיאור
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('123abc').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)

הגדרת כתובת ה-URL של הקישור לטווח התווים שצוין.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl(
    'https://docs.google.com/document/d/DOCUMENT_ID/edit',
);

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab('123abc').asDocumentTab().getBody();

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

פרמטרים

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

חזרה

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

אישור

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

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

setLinkUrl(url)

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

פרמטרים

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

חזרה

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('123abc').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('123abc').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.
const documentTab =
    DocumentApp.getActiveDocument().getActiveTab().asDocumentTab();
const 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.
const documentTab =
    DocumentApp.getActiveDocument().getActiveTab().asDocumentTab();
const 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('123abc').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