Class Text

טקסט

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

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

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

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

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

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

שיטות

‏Methodסוג החזרהתיאור קצר
appendText(text)Textהוספת הטקסט שצוין לסוף של אזור הטקסט הזה.
copy()Textמחזירה עותק מנותק ומעמיק של הרכיב הנוכחי.
deleteText(startOffset, endOffsetInclusive)Textמתבצעת מחיקה של טווח טקסט.
editAsText()Textקבלת גרסה Text של הרכיב הנוכחי לצורך עריכה.
findText(searchPattern)RangeElementמחפשת בתוכן של הרכיב את דפוס הטקסט שצוין באמצעות ביטויים רגולריים.
findText(searchPattern, from)RangeElementמחפשת בתוכן של הרכיב את דפוס הטקסט שצוין, החל מתוצאת חיפוש נתונה.
getAttributes()Objectאחזור של מאפייני הרכיב.
getAttributes(offset)Objectאחזור של המאפיינים בקיזוז התווים שצוין.
getBackgroundColor()Stringאחזור של הגדרת צבע הרקע.
getBackgroundColor(offset)Stringאחזור של צבע הרקע בקיזוז התווים שצוין.
getFontFamily()Stringאחזור של הגדרת משפחת הגופנים.
getFontFamily(offset)Stringאחזור של משפחת הגופנים בקיזוז התווים שצוין.
getFontSize()Numberאחזור של הגדרת גודל הגופן.
getFontSize(offset)Numberאחזור של גודל הגופן בקיזוז התווים שצוין.
getForegroundColor()Stringאחזור של הגדרת הצבע בחזית.
getForegroundColor(offset)Stringאחזור של צבע החזית בקיזוז התווים שצוין.
getLinkUrl()Stringאחזור של כתובת האתר של הקישור.
getLinkUrl(offset)Stringאחזור של כתובת ה-URL של הקישור בקיזוז התווים שצוין.
getNextSibling()Elementאחזור של פריט האחים הבא של הרכיב.
getParent()ContainerElementאחזור של רכיב ההורה של הרכיב.
getPreviousSibling()Elementאחזור של פריט האח הקודם של הרכיב.
getText()Stringאחזור של תוכן הרכיב כמחרוזת טקסט.
getTextAlignment()TextAlignmentמתקבלת יישור טקסט.
getTextAlignment(offset)TextAlignmentקבלת היישור של טקסט עבור תו אחד.
getTextAttributeIndices()Integer[]אחזור של קבוצת האינדקסים של טקסט שתואמת לתחילת העיצוב של טקסט ייחודי.
getType()ElementTypeמאחזר את ElementType של הרכיב.
insertText(offset, text)Textהוספת הטקסט שצוין בקיזוז התווים שצוין.
isAtDocumentEnd()Booleanקובע אם הרכיב נמצא בסוף ה-Document.
isBold()Booleanאחזור של ההגדרה המודגשת.
isBold(offset)Booleanאחזור של ההגדרה המודגשת בקיזוז התווים שצוין.
isItalic()Booleanאחזור של ההגדרה הנטויה.
isItalic(offset)Booleanאחזור של ההגדרה הנטוית בקיזוז תווים שצוין.
isStrikethrough()Booleanאחזור של הגדרת קו חוצה.
isStrikethrough(offset)Booleanאחזור של הגדרת קו חוצה בערך הקיזוז של התו שצוין.
isUnderline()Booleanאחזור של הגדרת הקו התחתון.
isUnderline(offset)Booleanאחזור של הגדרת הקו התחתון בקיזוז התווים שצוין.
merge()Textממזג את הרכיב עם האח הקודם מאותו סוג.
removeFromParent()Textהסרת הרכיב מההורה שלו.
replaceText(searchPattern, replacement)Elementהחלפת כל המופעים של תבנית טקסט נתונה במחרוזת החלפה נתונה, באמצעות ביטויים רגולריים.
setAttributes(startOffset, endOffsetInclusive, attributes)Textמחיל את המאפיינים שצוינו על טווח התווים הנתון.
setAttributes(attributes)Textמגדיר את מאפייני הרכיב.
setBackgroundColor(startOffset, endOffsetInclusive, color)Textהגדרת צבע הרקע של טווח התווים שצוין.
setBackgroundColor(color)Textהגדרת צבע הרקע.
setBold(bold)Textהגדרה מודגשת.
setBold(startOffset, endOffsetInclusive, bold)Textהגדרה מודגשת לטווח התווים שצוין.
setFontFamily(startOffset, endOffsetInclusive, fontFamilyName)Textהגדרת משפחת הגופנים לטווח התווים שצוין.
setFontFamily(fontFamilyName)Textהגדרת משפחת הגופנים.
setFontSize(startOffset, endOffsetInclusive, size)Textמגדיר את גודל הגופן עבור טווח התווים שצוין.
setFontSize(size)Textמגדיר את גודל הגופן.
setForegroundColor(startOffset, endOffsetInclusive, color)Textהגדרת צבע החזית עבור טווח התווים שצוין.
setForegroundColor(color)Textהגדרת צבע החזית.
setItalic(italic)Textקובע את ההגדרה של הגופן הנטוי.
setItalic(startOffset, endOffsetInclusive, italic)Textמגדיר את ההגדרה הנטויה בטווח התווים שצוין.
setLinkUrl(startOffset, endOffsetInclusive, url)Textהגדרת כתובת ה-URL של הקישור עבור טווח התווים שצוין.
setLinkUrl(url)Textהגדרת כתובת ה-URL של הקישור.
setStrikethrough(strikethrough)Textקביעת קו חוצה.
setStrikethrough(startOffset, endOffsetInclusive, strikethrough)Textקביעת קו חוצה עבור טווח התווים שצוין.
setText(text)Textמגדיר את תוכן הטקסט.
setTextAlignment(startOffset, endOffsetInclusive, textAlignment)Textהגדרת יישור הטקסט לטווח תווים נתון.
setTextAlignment(textAlignment)Textהגדרת יישור הטקסט.
setUnderline(underline)Textקביעת ההגדרה של הקו התחתון.
setUnderline(startOffset, endOffsetInclusive, underline)Textקובע את הגדרת הקו התחתון לטווח התווים שצוין.

מסמכים מפורטים

appendText(text)

הוספת הטקסט שצוין לסוף של אזור הטקסט הזה.

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

// Gets the document body.
const body = doc.getBody();

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

פרמטרים

שםסוגתיאור
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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

פרמטרים

שםסוגתיאור
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().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 — תוצאת חיפוש שמציינת את המיקום של טקסט החיפוש, או ריק אם אין התאמה

הרשאה

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

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

findText(searchPattern, from)

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

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

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

פרמטרים

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

הלוך ושוב

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

הרשאה

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

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

getAttributes()

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

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

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

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

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

// Log the paragraph attributes.
for (var att in atts) {
  Logger.log(att + ":" + atts[att]);
}

הלוך ושוב

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

הרשאה

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

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

getAttributes(offset)

אחזור של המאפיינים בקיזוז התווים שצוין.

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

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

// Gets the document body.
const body = doc.getBody();

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

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

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

פרמטרים

שםסוגתיאור
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/abc123456');

// Gets the document body.
const body = doc.getBody();

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

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

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

פרמטרים

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

הלוך ושוב

String — צבע הרקע, בפורמט CSS (כמו '#ffffff').

הרשאה

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

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

getFontFamily()

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

הלוך ושוב

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

הרשאה

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

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

getFontFamily(offset)

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

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

// Gets the document body.
const body = doc.getBody();

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

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

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

פרמטרים

שםסוגתיאור
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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

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

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

פרמטרים

שםסוגתיאור
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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

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

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

פרמטרים

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

הלוך ושוב

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

הרשאה

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

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

getLinkUrl()

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

הלוך ושוב

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

הרשאה

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

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

getLinkUrl(offset)

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

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

// Gets the document body.
const body = doc.getBody();

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

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

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

פרמטרים

שםסוגתיאור
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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

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

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

פרמטרים

שםסוגתיאור
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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

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

הלוך ושוב

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

הרשאה

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

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

getType()

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

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

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

// Obtain the first element in the document body.

var firstChild = body.getChild(0);

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

הלוך ושוב

ElementType — סוג הרכיב.

הרשאה

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

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

insertText(offset, text)

הוספת הטקסט שצוין בקיזוז התווים שצוין.

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

// Gets the document body.
const body = doc.getBody();

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

פרמטרים

שםסוגתיאור
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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

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

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

פרמטרים

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

הלוך ושוב

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

הרשאה

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

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

isItalic()

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

הלוך ושוב

Boolean — אם הטקסט נטוי או ריק אם הרכיב מכיל כמה ערכים עבור המאפיין הזה

הרשאה

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

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

isItalic(offset)

אחזור של ההגדרה הנטוית בקיזוז תווים שצוין.

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

// Gets the document body.
const body = doc.getBody();

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

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

פרמטרים

שםסוגתיאור
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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

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

פרמטרים

שםסוגתיאור
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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

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

פרמטרים

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

הלוך ושוב

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

הרשאה

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

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

merge()

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

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

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

var body = DocumentApp.getActiveDocument().getBody();
// Example 1: Merge paragraphs
// Append two paragraphs to the document.
var par1 = body.appendParagraph('Paragraph 1.');
var par2 = body.appendParagraph('Paragraph 2.');
// Merge the newly added paragraphs into a single paragraph.
par2.merge();

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

הלוך ושוב

Text — הרכיב שמוזג.

הרשאה

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

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

removeFromParent()

הסרת הרכיב מההורה שלו.

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

// Remove all images in the document body.
var imgs = body.getImages();
for (var i = 0; i < imgs.length; i++) {
  imgs[i].removeFromParent();
}

הלוך ושוב

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

הרשאה

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

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

replaceText(searchPattern, replacement)

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

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

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

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

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

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

פרמטרים

שםסוגתיאור
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/abc123456/edit');

// Gets the document body and edits as text.
const body = doc.getBody().editAsText();

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

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

פרמטרים

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

הלוך ושוב

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

הרשאה

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

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

setAttributes(attributes)

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

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

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

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

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

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

פרמטרים

שםסוגתיאור
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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

פרמטרים

שםסוגתיאור
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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

פרמטרים

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

הלוך ושוב

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

הרשאה

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

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

setFontFamily(startOffset, endOffsetInclusive, fontFamilyName)

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

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

// Gets body of the document.
const body = doc.getBody();

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

פרמטרים

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

הלוך ושוב

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

הרשאה

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

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

setFontFamily(fontFamilyName)

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

פרמטרים

שםסוגתיאור
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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

פרמטרים

שםסוגתיאור
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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

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

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

פרמטרים

שםסוגתיאור
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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

פרמטרים

שםסוגתיאור
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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

פרמטרים

שםסוגתיאור
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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

פרמטרים

שםסוגתיאור
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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

פרמטרים

שםסוגתיאור
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 be superscript.
var text = DocumentApp.getActiveDocument().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 be superscript.
var text = DocumentApp.getActiveDocument().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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

פרמטרים

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

הלוך ושוב

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

הרשאה

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

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