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

مواد و روش ها

روش نوع برگشت توضیح مختصر
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 آدرس لینک را تنظیم می کند.
setStrikethrough(strikethrough) Text تنظیم خط خطی را تنظیم می کند.
setStrikethrough(startOffset, endOffsetInclusive, strikethrough) Text تنظیم خط خطی را برای محدوده کاراکتر مشخص شده تنظیم می کند.
setText(text) Text محتوای متن را تنظیم می کند.
setTextAlignment(startOffset, endOffsetInclusive, textAlignment) Text تراز متن را برای یک محدوده کاراکتر معین تنظیم می کند.
setTextAlignment(textAlignment) Text تراز متن را تنظیم می کند.
setUnderline(underline) Text تنظیم زیر خط را تنظیم می کند.
setUnderline(startOffset, endOffsetInclusive, underline) Text تنظیم زیر خط را برای محدوده کاراکتر مشخص شده تنظیم می کند.

مستندات دقیق

appendText(text)

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

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

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

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

مولفه های

نام تایپ کنید شرح
text String متن برای پیوست

برگشت

Text - عنصر فعلی.

مجوز

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

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

copy()

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

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

برگشت

Text - کپی جدید.

مجوز

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

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

deleteText(startOffset, endOffsetInclusive)

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

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

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

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

مولفه های

نام تایپ کنید شرح
startOffset Integer آفست کاراکتر اولین نویسه ای که باید حذف شود.
endOffsetInclusive Integer افست کاراکتر آخرین کاراکتر برای حذف.

برگشت

Text - عنصر فعلی.

مجوز

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

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

editAsText()

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

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

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

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

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

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

برگشت

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


findText(searchPattern)

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

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

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

مولفه های

نام تایپ کنید شرح
searchPattern String الگوی جستجو

برگشت

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

مجوز

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

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

findText(searchPattern, from)

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

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

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

مولفه های

نام تایپ کنید شرح
searchPattern String الگوی جستجو
from RangeElement نتیجه جستجو برای جستجو از

برگشت

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

مجوز

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

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

getAttributes()

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

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

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

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

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

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

برگشت

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

مجوز

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

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

getAttributes(offset)

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

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

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

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

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

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

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

مولفه های

نام تایپ کنید شرح
offset Integer افست شخصیت.

برگشت

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

مجوز

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

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

getBackgroundColor()

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

برگشت

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

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

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

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

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

مولفه های

نام تایپ کنید شرح
offset Integer افست شخصیت.

برگشت

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

مجوز

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

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

getFontFamily()

تنظیم خانواده فونت را بازیابی می کند. نام می تواند هر قلمی از منوی فونت در Docs یا Google 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/abc123456/edit');

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

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

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

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

مولفه های

نام تایپ کنید شرح
offset Integer افست شخصیت.

برگشت

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

مجوز

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

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

getFontSize()

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

برگشت

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

مجوز

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

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

getFontSize(offset)

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

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

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

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

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

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

مولفه های

نام تایپ کنید شرح
offset Integer افست شخصیت.

برگشت

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

مجوز

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

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

getForegroundColor()

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

برگشت

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

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

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

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

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

مولفه های

نام تایپ کنید شرح
offset Integer افست شخصیت.

برگشت

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

مجوز

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

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

getLinkUrl()

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

برگشت

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

مجوز

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

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

getLinkUrl(offset)

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

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

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

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

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

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

مولفه های

نام تایپ کنید شرح
offset Integer افست شخصیت.

برگشت

String - URL پیوند.

مجوز

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

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

getNextSibling()

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

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

برگشت

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());

مولفه های

نام تایپ کنید شرح
offset Integer افست شخصیت.

برگشت

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

مجوز

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

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

getTextAttributeIndices()

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

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

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

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

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

برگشت

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

مجوز

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

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

getType()

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

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

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

// Obtain the first element in the document body.

var firstChild = body.getChild(0);

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

برگشت

ElementType - نوع عنصر.

مجوز

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

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

insertText(offset, text)

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

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

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

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

مولفه های

نام تایپ کنید شرح
offset Integer افست کاراکتر که در آن متن درج می شود.
text String متن برای درج

برگشت

Text - عنصر فعلی.

مجوز

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

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

isAtDocumentEnd()

تعیین می کند که آیا عنصر در انتهای 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);

مولفه های

نام تایپ کنید شرح
offset Integer افست شخصیت.

برگشت

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

مجوز

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

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

isItalic()

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

برگشت

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

مجوز

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

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

isItalic(offset)

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

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

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

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

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

مولفه های

نام تایپ کنید شرح
offset Integer افست شخصیت.

برگشت

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

مجوز

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

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

isStrikethrough()

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

برگشت

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

مجوز

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

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

isStrikethrough(offset)

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

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

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

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

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

مولفه های

نام تایپ کنید شرح
offset Integer افست شخصیت.

برگشت

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

مجوز

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

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

isUnderline()

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

برگشت

Boolean - اینکه آیا متن زیر خط کشیده شده باشد یا اگر عنصر حاوی مقادیر متعددی برای این ویژگی باشد، 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/abc123456/edit');

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

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

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

مولفه های

نام تایپ کنید شرح
offset Integer افست شخصیت.

برگشت

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

مجوز

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

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

merge()

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

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

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

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

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

برگشت

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

مجوز

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

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

removeFromParent()

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

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

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

برگشت

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

مجوز

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

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

replaceText(searchPattern, replacement)

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

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

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

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

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

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

مولفه های

نام تایپ کنید شرح
searchPattern String الگوی regex برای جستجو
replacement String متن برای استفاده به عنوان جایگزین

برگشت

Element - عنصر فعلی

مجوز

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

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

setAttributes(startOffset, endOffsetInclusive, attributes)

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

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

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

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

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

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

مولفه های

نام تایپ کنید شرح
startOffset Integer افست شروع محدوده متن.
endOffsetInclusive Integer آفست پایانی محدوده متن.
attributes Object ویژگی های عنصر

برگشت

Text - عنصر فعلی.

مجوز

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

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

setAttributes(attributes)

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

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

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

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

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

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

مولفه های

نام تایپ کنید شرح
attributes Object ویژگی های عنصر

برگشت

Text - عنصر فعلی.

مجوز

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

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

setBackgroundColor(startOffset, endOffsetInclusive, color)

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

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

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

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

مولفه های

نام تایپ کنید شرح
startOffset Integer افست شروع محدوده متن.
endOffsetInclusive Integer آفست پایانی محدوده متن.
color String رنگ پس زمینه، فرمت شده در نماد CSS (مانند '#ffffff' ).

برگشت

Text - عنصر فعلی.

مجوز

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

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

setBackgroundColor(color)

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

مولفه های

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

برگشت

Text - عنصر فعلی

مجوز

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

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

setBold(bold)

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

مولفه های

نام تایپ کنید شرح
bold Boolean تنظیم جسورانه

برگشت

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);

مولفه های

نام تایپ کنید شرح
startOffset Integer افست شروع محدوده متن.
endOffsetInclusive Integer آفست پایانی محدوده متن.
bold Boolean تنظیم جسورانه.

برگشت

Text - عنصر فعلی.

مجوز

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

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

setFontFamily(startOffset, endOffsetInclusive, fontFamilyName)

خانواده فونت را برای محدوده کاراکتر مشخص شده تنظیم می کند. نام می تواند هر قلمی از منوی فونت در Docs یا Google Fonts باشد و به حروف بزرگ و کوچک حساس است. نام فونت های ناشناس به صورت 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/abc123456/edit');

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

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

مولفه های

نام تایپ کنید شرح
startOffset Integer افست شروع محدوده متن.
endOffsetInclusive Integer آفست پایانی محدوده متن.
fontFamilyName String نام خانواده فونت، از منوی فونت در Docs یا Google Fonts.

برگشت

Text - عنصر فعلی.

مجوز

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

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

setFontFamily(fontFamilyName)

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

مولفه های

نام تایپ کنید شرح
fontFamilyName String نام خانواده فونت، از منوی فونت در Docs یا Google Fonts

برگشت

Text - عنصر فعلی

مجوز

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

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

setFontSize(startOffset, endOffsetInclusive, size)

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

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

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

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

مولفه های

نام تایپ کنید شرح
startOffset Integer افست شروع محدوده متن.
endOffsetInclusive Integer آفست پایانی محدوده متن.
size Number اندازه فونت

برگشت

Text - عنصر فعلی.

مجوز

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

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

setFontSize(size)

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

مولفه های

نام تایپ کنید شرح
size Number اندازه فونت

برگشت

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);

مولفه های

نام تایپ کنید شرح
startOffset Integer افست شروع محدوده متن.
endOffsetInclusive Integer آفست پایانی محدوده متن.
color String رنگ پیش زمینه، فرمت شده در نماد CSS (مانند '#ffffff' ).

برگشت

Text - عنصر فعلی.

مجوز

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

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

setForegroundColor(color)

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

مولفه های

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

برگشت

Text - عنصر فعلی

مجوز

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

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

setItalic(italic)

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

مولفه های

نام تایپ کنید شرح
italic Boolean تنظیم مورب

برگشت

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);

مولفه های

نام تایپ کنید شرح
startOffset Integer افست شروع محدوده متن.
endOffsetInclusive Integer آفست پایانی محدوده متن.
italic Boolean تنظیم مورب.

برگشت

Text - عنصر فعلی.

مجوز

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

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

setLinkUrl(startOffset, endOffsetInclusive, url)

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

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

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

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

مولفه های

نام تایپ کنید شرح
startOffset Integer افست شروع محدوده متن.
endOffsetInclusive Integer آفست پایانی محدوده متن.
url String آدرس لینک.

برگشت

Text - عنصر فعلی.

مجوز

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

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

setLinkUrl(url)

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

مولفه های

نام تایپ کنید شرح
url String آدرس لینک

برگشت

Text - عنصر فعلی

مجوز

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

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

setStrikethrough(strikethrough)

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

مولفه های

نام تایپ کنید شرح
strikethrough Boolean تنظیم خط عبور

برگشت

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);

مولفه های

نام تایپ کنید شرح
startOffset Integer افست شروع محدوده متن.
endOffsetInclusive Integer آفست پایانی محدوده متن.
strikethrough Boolean تنظیم خط عبور.

برگشت

Text - عنصر فعلی.

مجوز

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

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

setText(text)

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

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

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

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

مولفه های

نام تایپ کنید شرح
text String مطالب متن جدید

برگشت

Text - عنصر فعلی.

مجوز

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

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

setTextAlignment(startOffset, endOffsetInclusive, textAlignment)

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

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

مولفه های

نام تایپ کنید شرح
startOffset Integer آفست شروع محدوده کاراکتر.
endOffsetInclusive Integer افست پایانی محدوده کاراکتر (شامل).
textAlignment TextAlignment نوع تراز متنی که باید اعمال شود.

برگشت

Text - عنصر فعلی.

مجوز

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

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

setTextAlignment(textAlignment)

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

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

مولفه های

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

برگشت

Text - عنصر فعلی

مجوز

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

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

setUnderline(underline)

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

مولفه های

نام تایپ کنید شرح
underline Boolean تنظیم زیر خط

برگشت

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);

مولفه های

نام تایپ کنید شرح
startOffset Integer افست شروع محدوده متن.
endOffsetInclusive Integer آفست پایانی محدوده متن.
underline Boolean تنظیم زیر خط.

برگشت

Text - عنصر فعلی.

مجوز

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

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