Class Text

متن

عنصری که یک منطقه متن غنی را نشان می دهد. تمام متن در یک Document در عناصر Text موجود است. یک عنصر Text را می توان در یک Equation ، EquationFunction ، ListItem یا Paragraph قرار داد، اما خود نمی تواند حاوی هیچ عنصر دیگری باشد. برای اطلاعات بیشتر در مورد ساختار سند، راهنمای گسترش Google Docs را ببینید.

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

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

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

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

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

روش ها

روشنوع برگشتشرح مختصر
appendText(text)Textمتن مشخص شده را به انتهای این منطقه متن اضافه می کند.
copy()Textیک کپی جدا شده و عمیق از عنصر فعلی را برمی گرداند.
deleteText(startOffset, endOffsetInclusive)Textمحدوده ای از متن را حذف می کند.
editAsText()Textیک نسخه Text از عنصر فعلی را برای ویرایش دریافت می کند.
findText(searchPattern)RangeElementبا استفاده از عبارات منظم، محتویات عنصر را برای الگوی متن مشخص شده جستجو می کند.
findText(searchPattern, from)RangeElementمحتویات عنصر را برای الگوی متن مشخص شده، از یک نتیجه جستجوی معین شروع می کند.
getAttributes()Objectویژگی های عنصر را بازیابی می کند.
getAttributes(offset)Objectویژگی ها را در افست کاراکتر مشخص شده بازیابی می کند.
getBackgroundColor()Stringتنظیمات رنگ پس زمینه را بازیابی می کند.
getBackgroundColor(offset)Stringرنگ پس زمینه را با افست کاراکتر مشخص شده بازیابی می کند.
getFontFamily()Stringتنظیم خانواده فونت را بازیابی می کند.
getFontFamily(offset)Stringخانواده فونت را در افست کاراکتر مشخص شده بازیابی می کند.
getFontSize()Numberتنظیم اندازه فونت را بازیابی می کند.
getFontSize(offset)Numberاندازه فونت را با افست کاراکتر مشخص شده بازیابی می کند.
getForegroundColor()Stringتنظیم رنگ پیش زمینه را بازیابی می کند.
getForegroundColor(offset)Stringرنگ پیش زمینه را در افست کاراکتر مشخص شده بازیابی می کند.
getLinkUrl()Stringآدرس لینک را بازیابی می کند.
getLinkUrl(offset)StringURL پیوند را در فاصله کاراکتر مشخص شده بازیابی می کند.
getNextSibling()Elementعنصر خواهر و برادر بعدی عنصر را بازیابی می کند.
getParent()ContainerElementعنصر والد عنصر را بازیابی می کند.
getPreviousSibling()Elementعنصر خواهر و برادر قبلی عنصر را بازیابی می کند.
getText()Stringمحتویات عنصر را به عنوان یک رشته متنی بازیابی می کند.
getTextAlignment()TextAlignmentتراز متن را دریافت می کند.
getTextAlignment(offset)TextAlignmentتراز متن را برای یک کاراکتر دریافت می کند.
getTextAttributeIndices()Integer[]مجموعه ای از شاخص های متن را که با شروع اجراهای قالب بندی متن متمایز مطابقت دارند، بازیابی می کند.
getType()ElementTypeElementType عنصر را بازیابی می کند.
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)TextURL پیوند را برای محدوده کاراکتر مشخص شده تنظیم می کند.
setLinkUrl(url)Textآدرس لینک را تنظیم می کند.
setStrikethrough(strikethrough)Textتنظیم خط خطی را تنظیم می کند.
setStrikethrough(startOffset, endOffsetInclusive, strikethrough)Textتنظیم خط خطی را برای محدوده کاراکتر مشخص شده تنظیم می کند.
setText(text)Textمحتوای متن را تنظیم می کند.
setTextAlignment(startOffset, endOffsetInclusive, textAlignment)Textتراز متن را برای یک محدوده کاراکتر معین تنظیم می کند.
setTextAlignment(textAlignment)Textتراز متن را تنظیم می کند.
setUnderline(underline)Textتنظیم زیر خط را تنظیم می کند.
setUnderline(startOffset, endOffsetInclusive, underline)Textتنظیم زیر خط را برای محدوده کاراکتر مشخص شده تنظیم می کند.

مستندات دقیق

appendText(text)

متن مشخص شده را به انتهای این منطقه متن اضافه می کند.

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
textStringمتن برای پیوست

بازگشت

Text - عنصر فعلی.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

copy()

یک کپی جدا شده و عمیق از عنصر فعلی را برمی گرداند.

هر عنصر فرزند موجود در عنصر نیز کپی می شود. عنصر جدید والد ندارد.

بازگشت

Text - کپی جدید.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

deleteText(startOffset, endOffsetInclusive)

محدوده ای از متن را حذف می کند.

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
startOffsetIntegerآفست کاراکتر اولین نویسه ای که باید حذف شود.
endOffsetInclusiveIntegerافست کاراکتر آخرین کاراکتر برای حذف.

بازگشت

Text - عنصر فعلی.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

editAsText()

یک نسخه Text از عنصر فعلی را برای ویرایش دریافت می کند.

از editAsText برای دستکاری محتویات عناصر به عنوان متن غنی استفاده کنید. حالت editAsText عناصر غیر متنی (مانند InlineImage و HorizontalRule ) را نادیده می گیرد.

عناصر فرزند به طور کامل در محدوده متن حذف شده از عنصر حذف می شوند.

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

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

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

بازگشت

Text - نسخه متنی عنصر فعلی


findText(searchPattern)

با استفاده از عبارات منظم، محتویات عنصر را برای الگوی متن مشخص شده جستجو می کند.

زیرمجموعه ای از ویژگی های عبارت منظم جاوا اسکریپت به طور کامل پشتیبانی نمی شود، مانند گروه های ضبط و اصلاح کننده های حالت.

الگوی عبارت منظم ارائه شده به طور مستقل با هر بلوک متن موجود در عنصر فعلی مطابقت دارد.

پارامترها

نامتایپ کنیدتوضیحات
searchPatternStringالگوی مورد جستجو

بازگشت

RangeElement - یک نتیجه جستجو که موقعیت متن جستجو را نشان می دهد، یا اگر مطابقت نداشته باشد، پوچ است

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

findText(searchPattern, from)

محتویات عنصر را برای الگوی متن مشخص شده، از یک نتیجه جستجوی معین شروع می کند.

زیرمجموعه ای از ویژگی های عبارت منظم جاوا اسکریپت به طور کامل پشتیبانی نمی شود، مانند گروه های ضبط و اصلاح کننده های حالت.

الگوی عبارت منظم ارائه شده به طور مستقل با هر بلوک متن موجود در عنصر فعلی مطابقت دارد.

پارامترها

نامتایپ کنیدتوضیحات
searchPatternStringالگوی جستجو
fromRangeElementنتیجه جستجو برای جستجو از

بازگشت

RangeElement - یک نتیجه جستجو که موقعیت بعدی متن جستجو را نشان می دهد، یا اگر مطابقت نداشته باشد، پوچ است

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getAttributes()

ویژگی های عنصر را بازیابی می کند.

نتیجه یک شی حاوی یک ویژگی برای هر ویژگی عنصر معتبر است که در آن نام هر ویژگی با یک مورد در شمارش DocumentApp.Attribute مطابقت دارد.

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

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

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

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

بازگشت

Object - ویژگی های عنصر.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getAttributes(offset)

ویژگی ها را در افست کاراکتر مشخص شده بازیابی می کند.

نتیجه یک شی حاوی یک ویژگی برای هر ویژگی متن معتبر است که در آن نام هر ویژگی با یک مورد در شمارش DocumentApp.Attribute مطابقت دارد.

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

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

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
offsetIntegerافست شخصیت.

بازگشت

Object - ویژگی های عنصر.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getBackgroundColor()

تنظیمات رنگ پس زمینه را بازیابی می کند.

بازگشت

String - رنگ پس‌زمینه، قالب‌بندی شده در نماد CSS (مانند '#ffffff' )، یا اگر عنصر حاوی مقادیر متعددی برای این ویژگی باشد، 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(TAB_ID).asDocumentTab().getBody();

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
offsetIntegerافست شخصیت.

بازگشت

String - رنگ پس زمینه، فرمت شده در نماد CSS (مانند '#ffffff' ).

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getFontFamily()

تنظیم خانواده فونت را بازیابی می کند. نام می تواند هر قلمی از منوی فونت در Docs یا Google Fonts باشد و به حروف بزرگ و کوچک حساس است. متدهای getFontFamily() و setFontFamily(fontFamilyName) اکنون از نام رشته ها برای فونت ها به جای FontFamily enum استفاده می کنند. اگرچه این فهرست منسوخ شده است، اما برای سازگاری با اسکریپت های قدیمی در دسترس باقی خواهد ماند.

بازگشت

String - خانواده فونت، یا اگر عنصر حاوی مقادیر متعددی برای این ویژگی باشد، null است

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getFontFamily(offset)

خانواده فونت را در افست کاراکتر مشخص شده بازیابی می کند. نام می تواند هر قلمی از منوی فونت در Docs یا Google Fonts باشد و به حروف بزرگ و کوچک حساس است. متدهای getFontFamily() و setFontFamily(fontFamilyName) اکنون از نام رشته ها برای فونت ها به جای FontFamily enum استفاده می کنند. اگرچه این فهرست منسوخ شده است، اما برای سازگاری با اسکریپت های قدیمی در دسترس باقی خواهد ماند.

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

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

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
offsetIntegerافست شخصیت.

بازگشت

String - خانواده فونت.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getFontSize()

تنظیم اندازه فونت را بازیابی می کند.

بازگشت

Number - اندازه قلم، یا اگر عنصر حاوی مقادیر متعددی برای این ویژگی باشد، null است

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getFontSize(offset)

اندازه فونت را با افست کاراکتر مشخص شده بازیابی می کند.

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

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

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
offsetIntegerافست شخصیت.

بازگشت

Number - اندازه فونت

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getForegroundColor()

تنظیم رنگ پیش زمینه را بازیابی می کند.

بازگشت

String - رنگ پیش زمینه، قالب بندی شده در نماد CSS (مانند '#ffffff' )، یا اگر عنصر حاوی مقادیر متعددی برای این ویژگی باشد، 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(TAB_ID).asDocumentTab().getBody();

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
offsetIntegerافست شخصیت.

بازگشت

String - رنگ پیش زمینه، فرمت شده در نماد CSS (مانند '#ffffff' ).

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getLinkUrl()

آدرس لینک را بازیابی می کند.

بازگشت

String - URL پیوند یا اگر عنصر حاوی مقادیر متعددی برای این ویژگی باشد، null است

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getLinkUrl(offset)

URL پیوند را در فاصله کاراکتر مشخص شده بازیابی می کند.

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

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

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
offsetIntegerافست شخصیت.

بازگشت

String - URL پیوند.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getNextSibling()

عنصر خواهر و برادر بعدی عنصر را بازیابی می کند.

خواهر و برادر بعدی همان والد را دارد و از عنصر فعلی پیروی می کند.

بازگشت

Element - عنصر خواهر و برادر بعدی.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getParent()

عنصر والد عنصر را بازیابی می کند.

عنصر والد حاوی عنصر فعلی است.

بازگشت

ContainerElement - عنصر والد.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getPreviousSibling()

عنصر خواهر و برادر قبلی عنصر را بازیابی می کند.

خواهر و برادر قبلی والد مشابهی دارد و مقدم بر عنصر فعلی است.

بازگشت

Element - عنصر خواهر و برادر قبلی.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getText()

محتویات عنصر را به عنوان یک رشته متنی بازیابی می کند.

بازگشت

String - محتویات عنصر به عنوان رشته متن

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getTextAlignment()

تراز متن را دریافت می کند. انواع موجود ترازها DocumentApp.TextAlignment.NORMAL ، DocumentApp.TextAlignment.SUBSCRIPT و DocumentApp.TextAlignment.SUPERSCRIPT هستند.

بازگشت

TextAlignment - نوع هم‌ترازی متن، یا اگر متن حاوی چندین نوع هم‌ترازی متن باشد یا اگر تراز متن هرگز تنظیم نشده باشد، null

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getTextAlignment(offset)

تراز متن را برای یک کاراکتر دریافت می کند. انواع موجود ترازها DocumentApp.TextAlignment.NORMAL ، DocumentApp.TextAlignment.SUBSCRIPT و DocumentApp.TextAlignment.SUPERSCRIPT هستند.

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

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

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
offsetIntegerافست شخصیت.

بازگشت

TextAlignment - نوع هم ترازی متن، یا اگر تراز متن هرگز تنظیم نشده باشد، null .

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getTextAttributeIndices()

مجموعه ای از شاخص های متن را که با شروع اجراهای قالب بندی متن متمایز مطابقت دارد، بازیابی می کند.

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

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

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

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

بازگشت

Integer[] - مجموعه ای از شاخص های متنی که در آن قالب بندی متن تغییر می کند.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

getType()

ElementType عنصر را بازیابی می کند.

از getType() برای تعیین نوع دقیق یک عنصر استفاده کنید.

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

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

var firstChild = body.getChild(0);

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

بازگشت

ElementType - نوع عنصر.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

insertText(offset, text)

متن مشخص شده را در افست کاراکتر داده شده درج می کند.

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
offsetIntegerافست کاراکتر که در آن متن درج می شود.
textStringمتن برای درج

بازگشت

Text - عنصر فعلی.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

isAtDocumentEnd()

تعیین می کند که آیا عنصر در انتهای Document قرار دارد یا خیر.

بازگشت

Boolean - اینکه آیا عنصر در انتهای برگه است.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

isBold()

تنظیم پررنگ را بازیابی می کند.

بازگشت

Boolean - اگر متن دارای مقادیر متعددی برای این ویژگی باشد، متن پررنگ باشد یا تهی

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

isBold(offset)

تنظیم پررنگ را در افست کاراکتر مشخص شده بازیابی می کند.

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

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

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
offsetIntegerافست شخصیت.

بازگشت

Boolean - تنظیم پررنگ.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

isItalic()

تنظیمات ایتالیک را بازیابی می کند.

بازگشت

Boolean - آیا متن ایتالیک است یا تهی اگر عنصر حاوی چندین مقدار برای این ویژگی باشد

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

isItalic(offset)

تنظیمات ایتالیک را در افست کاراکتر مشخص شده بازیابی می کند.

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

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
offsetIntegerافست شخصیت.

بازگشت

Boolean - تنظیم ایتالیک.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

isStrikethrough()

تنظیم خط خطی را بازیابی می کند.

بازگشت

Boolean - آیا متن خط خطی است، یا تهی اگر عنصر حاوی مقادیر متعددی برای این ویژگی باشد

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

isStrikethrough(offset)

تنظیم خط خطی را در افست کاراکتر مشخص شده بازیابی می کند.

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

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
offsetIntegerافست شخصیت.

بازگشت

Boolean - تنظیم خط خطی.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

isUnderline()

تنظیم زیر خط را بازیابی می کند.

بازگشت

Boolean - اینکه آیا متن زیر خط کشیده شده باشد یا اگر عنصر حاوی مقادیر متعددی برای این ویژگی باشد، 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(TAB_ID).asDocumentTab().getBody();

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

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

پارامترها

نامتایپ کنیدتوضیحات
offsetIntegerافست شخصیت.

بازگشت

Boolean - تنظیم زیر خط.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

merge()

عنصر را با خواهر و برادر قبلی از همان نوع ادغام می کند.

فقط عناصر همان ElementType را می توان ادغام کرد. هر عنصر فرزند موجود در عنصر فعلی به عنصر خواهر و برادر قبلی منتقل می شود.

عنصر فعلی از سند حذف می شود.

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

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

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

بازگشت

Text - عنصر ادغام شده.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

removeFromParent()

عنصر را از والد خود حذف می کند.

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

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

بازگشت

Text - عنصر حذف شده.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

replaceText(searchPattern, replacement)

با استفاده از عبارات منظم، تمام رخدادهای یک الگوی متنی را با یک رشته جایگزین معین جایگزین می‌کند.

الگوی جستجو به عنوان یک رشته ارسال می شود، نه یک شیء عبارت منظم جاوا اسکریپت. به همین دلیل شما باید از هر گونه بک اسلش در الگو فرار کنید.

این روش از کتابخانه عبارات منظم RE2 گوگل استفاده می کند که نحو پشتیبانی شده را محدود می کند.

الگوی عبارت منظم ارائه شده به طور مستقل با هر بلوک متن موجود در عنصر فعلی مطابقت دارد.

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

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

پارامترها

نامتایپ کنیدتوضیحات
searchPatternStringالگوی regex برای جستجو
replacementStringمتن برای استفاده به عنوان جایگزین

بازگشت

Element - عنصر فعلی

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setAttributes(startOffset, endOffsetInclusive, attributes)

ویژگی های مشخص شده را در محدوده کاراکتر داده شده اعمال می کند.

پارامتر مشخصه مشخص شده باید یک شی باشد که در آن نام هر ویژگی یک مورد در شمارش DocumentApp.Attribute باشد و هر مقدار ویژگی مقدار جدیدی است که باید اعمال شود.

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

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
startOffsetIntegerافست شروع محدوده متن.
endOffsetInclusiveIntegerآفست پایانی محدوده متن.
attributesObjectویژگی های عنصر

بازگشت

Text - عنصر فعلی.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setAttributes(attributes)

ویژگی های عنصر را تنظیم می کند.

پارامتر مشخصه مشخص شده باید یک شی باشد که در آن نام هر ویژگی یک مورد در شمارش DocumentApp.Attribute باشد و هر مقدار ویژگی مقدار جدیدی است که باید اعمال شود.

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

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
attributesObjectویژگی های عنصر

بازگشت

Text - عنصر فعلی.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setBackgroundColor(startOffset, endOffsetInclusive, color)

رنگ پس زمینه را برای محدوده کاراکتر مشخص شده تنظیم می کند.

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
startOffsetIntegerافست شروع محدوده متن.
endOffsetInclusiveIntegerآفست پایانی محدوده متن.
colorStringرنگ پس زمینه، فرمت شده در نماد CSS (مانند '#ffffff' ).

بازگشت

Text - عنصر فعلی.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setBackgroundColor(color)

رنگ پس زمینه را تنظیم می کند.

پارامترها

نامتایپ کنیدتوضیحات
colorStringرنگ پس زمینه، فرمت شده در نماد CSS (مانند '#ffffff' )

بازگشت

Text - عنصر فعلی

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setBold(bold)

تنظیم پررنگ را تنظیم می کند.

پارامترها

نامتایپ کنیدتوضیحات
boldBooleanتنظیم جسورانه

بازگشت

Text - عنصر فعلی

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setBold(startOffset, endOffsetInclusive, bold)

تنظیم پررنگ را برای محدوده کاراکتر مشخص شده تنظیم می کند.

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
startOffsetIntegerافست شروع محدوده متن.
endOffsetInclusiveIntegerآفست پایانی محدوده متن.
boldBooleanتنظیم جسورانه.

بازگشت

Text - عنصر فعلی.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setFontFamily(startOffset, endOffsetInclusive, fontFamilyName)

خانواده فونت را برای محدوده کاراکتر مشخص شده تنظیم می کند. نام می تواند هر قلمی از منوی فونت در Docs یا Google Fonts باشد و به حروف بزرگ و کوچک حساس است. نام فونت های ناشناس به صورت Arial ارائه می شود. روش‌های getFontFamily(offset) و setFontFamily(fontFamilyName) اکنون از نام رشته‌ای برای فونت‌ها به جای FontFamily enum استفاده می‌کنند. اگرچه این فهرست منسوخ شده است، اما برای سازگاری با اسکریپت های قدیمی در دسترس خواهد بود.

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
startOffsetIntegerافست شروع محدوده متن.
endOffsetInclusiveIntegerآفست پایانی محدوده متن.
fontFamilyNameStringنام خانواده فونت، از منوی فونت در Docs یا Google Fonts.

بازگشت

Text - عنصر فعلی.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setFontFamily(fontFamilyName)

خانواده فونت را تنظیم می کند. نام می تواند هر قلمی از منوی فونت در Docs یا Google Fonts باشد و به حروف بزرگ و کوچک حساس است. نام فونت های ناشناس به صورت Arial ارائه می شود. متدهای getFontFamily() و setFontFamily(fontFamilyName) اکنون از نام رشته ها برای فونت ها به جای FontFamily enum استفاده می کنند. اگرچه این فهرست منسوخ شده است، اما برای سازگاری با اسکریپت های قدیمی در دسترس باقی خواهد ماند.

پارامترها

نامتایپ کنیدتوضیحات
fontFamilyNameStringنام خانواده فونت، از منوی فونت در Docs یا Google Fonts

بازگشت

Text - عنصر فعلی

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setFontSize(startOffset, endOffsetInclusive, size)

اندازه قلم را برای محدوده کاراکتر مشخص شده تنظیم می کند.

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
startOffsetIntegerافست شروع محدوده متن.
endOffsetInclusiveIntegerآفست پایانی محدوده متن.
sizeNumberاندازه فونت

بازگشت

Text - عنصر فعلی.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setFontSize(size)

اندازه فونت را تنظیم می کند.

پارامترها

نامتایپ کنیدتوضیحات
sizeNumberاندازه فونت

بازگشت

Text - عنصر فعلی

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setForegroundColor(startOffset, endOffsetInclusive, color)

رنگ پیش زمینه را برای محدوده کاراکتر مشخص شده تنظیم می کند.

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

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

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
startOffsetIntegerافست شروع محدوده متن.
endOffsetInclusiveIntegerآفست پایانی محدوده متن.
colorStringرنگ پیش زمینه، فرمت شده در نماد CSS (مانند '#ffffff' ).

بازگشت

Text - عنصر فعلی.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setForegroundColor(color)

رنگ پیش زمینه را تنظیم می کند.

پارامترها

نامتایپ کنیدتوضیحات
colorStringرنگ پیش زمینه، فرمت شده در نماد CSS (مانند '#ffffff' )

بازگشت

Text - عنصر فعلی

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setItalic(italic)

تنظیمات ایتالیک را تنظیم می کند.

پارامترها

نامتایپ کنیدتوضیحات
italicBooleanتنظیم مورب

بازگشت

Text - عنصر فعلی

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setItalic(startOffset, endOffsetInclusive, italic)

تنظیمات ایتالیک را برای محدوده کاراکتر مشخص شده تنظیم می کند.

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
startOffsetIntegerافست شروع محدوده متن.
endOffsetInclusiveIntegerآفست پایانی محدوده متن.
italicBooleanتنظیم مورب.

بازگشت

Text - عنصر فعلی.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setLinkUrl(startOffset, endOffsetInclusive, url)

URL پیوند را برای محدوده کاراکتر مشخص شده تنظیم می کند.

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
startOffsetIntegerافست شروع محدوده متن.
endOffsetInclusiveIntegerآفست پایانی محدوده متن.
urlStringآدرس لینک.

بازگشت

Text - عنصر فعلی.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setLinkUrl(url)

آدرس لینک را تنظیم می کند.

پارامترها

نامتایپ کنیدتوضیحات
urlStringآدرس لینک

بازگشت

Text - عنصر فعلی

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setStrikethrough(strikethrough)

تنظیم خط خطی را تنظیم می کند.

پارامترها

نامتایپ کنیدتوضیحات
strikethroughBooleanتنظیم خط عبور

بازگشت

Text - عنصر فعلی

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setStrikethrough(startOffset, endOffsetInclusive, strikethrough)

تنظیم خط خطی را برای محدوده کاراکتر مشخص شده تنظیم می کند.

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
startOffsetIntegerافست شروع محدوده متن.
endOffsetInclusiveIntegerآفست پایانی محدوده متن.
strikethroughBooleanتنظیم خط عبور.

بازگشت

Text - عنصر فعلی.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setText(text)

محتوای متن را تنظیم می کند.

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
textStringمطالب متن جدید

بازگشت

Text - عنصر فعلی.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setTextAlignment(startOffset, endOffsetInclusive, textAlignment)

تراز متن را برای یک محدوده کاراکتر معین تنظیم می کند. انواع موجود ترازها DocumentApp.TextAlignment.NORMAL ، DocumentApp.TextAlignment.SUBSCRIPT و DocumentApp.TextAlignment.SUPERSCRIPT هستند.

// Make the first character in the first paragraph of the active tab be superscript.
var documentTab = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab();
var text = documentTab.getBody().getParagraphs()[0].editAsText();
text.setTextAlignment(0, 0, DocumentApp.TextAlignment.SUPERSCRIPT);

پارامترها

نامتایپ کنیدتوضیحات
startOffsetIntegerآفست شروع محدوده کاراکتر.
endOffsetInclusiveIntegerافست پایانی محدوده کاراکتر (شامل).
textAlignmentTextAlignmentنوع تراز متنی که باید اعمال شود.

بازگشت

Text - عنصر فعلی.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setTextAlignment(textAlignment)

تراز متن را تنظیم می کند. انواع موجود ترازها DocumentApp.TextAlignment.NORMAL ، DocumentApp.TextAlignment.SUBSCRIPT و DocumentApp.TextAlignment.SUPERSCRIPT هستند.

// Make the entire first paragraph in the active tab be superscript.
var documentTab = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab();
var text = documentTab.getBody().getParagraphs()[0].editAsText();
text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);

پارامترها

نامتایپ کنیدتوضیحات
textAlignmentTextAlignmentنوع تراز متنی که باید اعمال شود

بازگشت

Text - عنصر فعلی

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setUnderline(underline)

تنظیم زیر خط را تنظیم می کند.

پارامترها

نامتایپ کنیدتوضیحات
underlineBooleanتنظیم زیر خط

بازگشت

Text - عنصر فعلی

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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

setUnderline(startOffset, endOffsetInclusive, underline)

تنظیم زیر خط را برای محدوده کاراکتر مشخص شده تنظیم می کند.

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

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

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

پارامترها

نامتایپ کنیدتوضیحات
startOffsetIntegerافست شروع محدوده متن.
endOffsetInclusiveIntegerافست پایانی محدوده متن.
underlineBooleanتنظیم زیر خط.

بازگشت

Text - عنصر فعلی.

مجوز

اسکریپت هایی که از این روش استفاده می کنند نیاز به مجوز با یک یا چند مورد از حوزه های زیر دارند:

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