عنصری که نشاندهنده یک ناحیه متنی غنی است. تمام متن موجود در یک Document درون عناصر Text قرار دارد. یک عنصر Text میتواند درون یک Equation ، تابع معادله Equation Function ، List Item ) یا Paragraph قرار گیرد، اما نمیتواند خود شامل هیچ عنصر دیگری باشد. برای اطلاعات بیشتر در مورد ساختار سند، به راهنمای توسعه Google Docs مراجعه کنید.
// Gets the body contents of the active tab. const body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody(); // Use editAsText to obtain a single text element containing // all the characters in the tab. const text = body.editAsText(); // Insert text at the beginning of the tab. text.insertText(0, 'Inserted text.\n'); // Insert text at the end of the tab. text.appendText('\nAppended text.'); // Make the first half of the tab blue. text.setForegroundColor(0, text.getText().length / 2, '#00FFFF');
روشها
| روش | نوع بازگشتی | شرح مختصر |
|---|---|---|
append Text(text) | Text | متن مشخص شده را به انتهای این ناحیه متنی اضافه میکند. |
copy() | Text | یک کپی جدا و عمیق از عنصر فعلی را برمیگرداند. |
delete Text(startOffset, endOffsetInclusive) | Text | محدودهای از متن را حذف میکند. |
edit As Text() | Text | یک نسخه Text از عنصر فعلی را برای ویرایش دریافت میکند. |
find Text(searchPattern) | Range Element |null | با استفاده از عبارات منظم، محتوای عنصر را برای الگوی متنی مشخص شده جستجو میکند. |
find Text(searchPattern, from) | Range Element |null | با شروع از یک نتیجه جستجوی داده شده، محتویات عنصر را برای الگوی متنی مشخص شده جستجو میکند. |
get Attributes() | Object | ویژگیهای عنصر را بازیابی میکند. |
get Attributes(offset) | Object | ویژگیها را در فاصلهی کاراکتری مشخصشده بازیابی میکند. |
get Background Color() | String|null | تنظیمات رنگ پسزمینه را بازیابی میکند. |
get Background Color(offset) | String|null | رنگ پسزمینه را در فاصلهی کاراکتری مشخصشده بازیابی میکند. |
get Font Family() | String|null | تنظیمات خانواده فونت را بازیابی میکند. |
get Font Family(offset) | String|null | خانواده فونت را در فاصلهی کاراکتری مشخص شده بازیابی میکند. |
get Font Size() | Number|null | تنظیم اندازه فونت را بازیابی میکند. |
get Font Size(offset) | Number|null | اندازه فونت را در فاصله کاراکتری مشخص شده بازیابی میکند. |
get Foreground Color() | String|null | تنظیمات رنگ پیشزمینه را بازیابی میکند. |
get Foreground Color(offset) | String|null | رنگ پیشزمینه را در فاصلهی کاراکتری مشخصشده بازیابی میکند. |
get Link Url() | String|null | آدرس لینک را بازیابی میکند. |
get Link Url(offset) | String|null | آدرس اینترنتی (URL) لینک را در فاصلهی کاراکتری مشخص شده بازیابی میکند. |
get Next Sibling() | Element |null | عنصر خواهر یا برادر بعدی عنصر را بازیابی میکند. |
get Parent() | Container Element |null | عنصر والد عنصر را بازیابی میکند. |
get Previous Sibling() | Element |null | عنصر خواهر و برادر قبلی عنصر را بازیابی میکند. |
get Text() | String | محتوای عنصر را به صورت یک رشته متنی بازیابی میکند. |
get Text Alignment() | Text Alignment |null | ترازبندی متن را دریافت میکند. |
get Text Alignment(offset) | Text Alignment |null | ترازبندی متن را برای یک کاراکتر واحد دریافت میکند. |
get Text Attribute Indices() | Integer[] | مجموعهای از اندیسهای متن را که مربوط به شروع اجرای قالببندی متن متمایز هستند، بازیابی میکند. |
get Type() | Element Type | Element Type را بازیابی میکند. |
insert Text(offset, text) | Text | متن مشخص شده را در فاصلهی کاراکتری داده شده درج میکند. |
is At Document End() | Boolean | تعیین میکند که آیا عنصر در انتهای Document قرار دارد یا خیر. |
is Bold() | Boolean|null | تنظیمات پررنگ را بازیابی میکند. |
is Bold(offset) | Boolean|null | تنظیمات پررنگ را در فاصلهی کاراکتر مشخصشده بازیابی میکند. |
is Italic() | Boolean|null | تنظیمات ایتالیک را بازیابی میکند. |
is Italic(offset) | Boolean|null | تنظیمات ایتالیک را در فاصلهی کاراکتری مشخصشده بازیابی میکند. |
is Strikethrough() | Boolean|null | تنظیمات خط خورده را بازیابی میکند. |
is Strikethrough(offset) | Boolean|null | تنظیمات خطخوردگی را در فاصلهی کاراکتری مشخصشده بازیابی میکند. |
is Underline() | Boolean|null | تنظیمات زیرخط را بازیابی میکند. |
is Underline(offset) | Boolean|null | تنظیمات زیرخط را در فاصلهی کاراکتری مشخصشده بازیابی میکند. |
merge() | Text |null | عنصر را با عنصر خواهر یا برادر قبلی از همان نوع ادغام میکند. |
remove From Parent() | Text |null | عنصر را از والدش حذف میکند. |
replace Text(searchPattern, replacement) | Element | با استفاده از عبارات منظم، تمام موارد تکرار یک الگوی متنی مشخص را با یک رشته جایگزین مشخص جایگزین میکند. |
set Attributes(startOffset, endOffsetInclusive, attributes) | Text | ویژگیهای مشخصشده را به محدوده کاراکتر دادهشده اعمال میکند. |
set Attributes(attributes) | Text | ویژگیهای عنصر را تنظیم میکند. |
set Background Color(startOffset, endOffsetInclusive, color) | Text | رنگ پسزمینه را برای محدوده کاراکتر مشخص شده تنظیم میکند. |
set Background Color(color) | Text | رنگ پس زمینه را تنظیم میکند. |
set Bold(bold) | Text | تنظیمات پررنگ را تنظیم میکند. |
set Bold(startOffset, endOffsetInclusive, bold) | Text | تنظیمات پررنگ بودن را برای محدوده کاراکتر مشخص شده تنظیم میکند. |
set Font Family(startOffset, endOffsetInclusive, fontFamilyName) | Text | خانواده فونت را برای محدوده کاراکتر مشخص شده تنظیم میکند. |
set Font Family(fontFamilyName) | Text | خانواده فونت را تنظیم میکند. |
set Font Size(startOffset, endOffsetInclusive, size) | Text | اندازه فونت را برای محدوده کاراکتر مشخص شده تنظیم میکند. |
set Font Size(size) | Text | اندازه فونت را تنظیم میکند. |
set Foreground Color(startOffset, endOffsetInclusive, color) | Text | رنگ پیشزمینه را برای محدوده کاراکتر مشخص شده تنظیم میکند. |
set Foreground Color(color) | Text | رنگ پیشزمینه را تنظیم میکند. |
set Italic(italic) | Text | حالت ایتالیک را تنظیم میکند. |
set Italic(startOffset, endOffsetInclusive, italic) | Text | تنظیمات ایتالیک را برای محدوده کاراکتر مشخص شده تنظیم میکند. |
set Link Url(startOffset, endOffsetInclusive, url) | Text | آدرس اینترنتی (URL) لینک را برای محدوده کاراکتری مشخص شده تنظیم میکند. |
set Link Url(url) | Text | آدرس لینک را تنظیم میکند. |
set Strikethrough(strikethrough) | Text | تنظیمات خط خورده را تنظیم میکند. |
set Strikethrough(startOffset, endOffsetInclusive, strikethrough) | Text | تنظیمات خطخوردگی را برای محدوده کاراکتر مشخصشده تنظیم میکند. |
set Text(text) | Text | محتوای متن را تنظیم میکند. |
set Text Alignment(startOffset, endOffsetInclusive, textAlignment) | Text | ترازبندی متن را برای یک محدوده کاراکتری مشخص تنظیم میکند. |
set Text Alignment(textAlignment) | Text | ترازبندی متن را تنظیم میکند. |
set Underline(underline) | Text | تنظیمات زیرخط را تنظیم میکند. |
set Underline(startOffset, endOffsetInclusive, underline) | Text | تنظیمات زیرخط را برای محدوده کاراکتر مشخص شده تنظیم میکند. |
مستندات دقیق
append Text(text)
متن مشخص شده را به انتهای این ناحیه متنی اضافه میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Adds the text, 'Sample body text,' to the end of the tab body. const text = body.editAsText().appendText('Sample body text');
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
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
delete Text(startOffset, endOffsetInclusive)
محدودهای از متن را حذف میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Deletes the first 10 characters in the body. const text = body.editAsText().deleteText(0, 9);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
start Offset | Integer | فاصلهی کاراکتری اولین کاراکتری که باید حذف شود. |
end Offset Inclusive | Integer | آفست کاراکتر آخرین کاراکتری که باید حذف شود. |
بازگشت
Text - عنصر فعلی.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
edit As Text()
یک نسخه Text از عنصر فعلی را برای ویرایش دریافت میکند.
edit As Text برای دستکاری محتوای عناصر به عنوان متن غنی استفاده کنید. حالت edit As Text عناصر غیر متنی (مانند Inline Image و Horizontal Rule ) را نادیده میگیرد.
عناصر فرزندی که کاملاً در محدوده متن حذف شده قرار دارند، از عنصر حذف میشوند.
const body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody(); // Insert two paragraphs separated by a paragraph containing an // horizontal rule. body.insertParagraph(0, 'An editAsText sample.'); body.insertHorizontalRule(0); body.insertParagraph(0, 'An example.'); // Delete " sample.\n\n An" removing the horizontal rule in the process. body.editAsText().deleteText(14, 25);
بازگشت
Text - نسخه متنی عنصر فعلی
find Text(searchPattern)
با استفاده از عبارات منظم، محتوای عنصر را برای الگوی متنی مشخص شده جستجو میکند.
زیرمجموعهای از ویژگیهای عبارات منظم جاوا اسکریپت به طور کامل پشتیبانی نمیشوند، مانند گروههای ضبط و اصلاحکنندههای حالت.
الگوی عبارت منظم ارائه شده به طور مستقل با هر بلوک متنی موجود در عنصر فعلی مطابقت داده میشود.
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
search Pattern | String | الگویی که باید جستجو شود |
بازگشت
Range Element |null — نتیجه جستجو که موقعیت متن جستجو را نشان میدهد، یا در صورت عدم تطابق، null
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
find Text(searchPattern, from)
با شروع از یک نتیجه جستجوی داده شده، محتویات عنصر را برای الگوی متنی مشخص شده جستجو میکند.
زیرمجموعهای از ویژگیهای عبارات منظم جاوا اسکریپت به طور کامل پشتیبانی نمیشوند، مانند گروههای ضبط و اصلاحکنندههای حالت.
الگوی عبارت منظم ارائه شده به طور مستقل با هر بلوک متنی موجود در عنصر فعلی مطابقت داده میشود.
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
search Pattern | String | الگویی که باید جستجو شود |
from | Range Element | نتیجه جستجو برای جستجو از |
بازگشت
Range Element |null — نتیجه جستجو که موقعیت بعدی متن جستجو را نشان میدهد، یا در صورت عدم تطابق، null است.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Attributes()
ویژگیهای عنصر را بازیابی میکند.
نتیجه، یک شیء حاوی یک ویژگی برای هر ویژگی عنصر معتبر است که در آن هر نام ویژگی با یک آیتم در شمارش Document App.Attribute مطابقت دارد.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Append a styled paragraph. const par = body.appendParagraph('A bold, italicized paragraph.'); par.setBold(true); par.setItalic(true); // Retrieve the paragraph's attributes. const atts = par.getAttributes(); // Log the paragraph attributes. for (const att in atts) { Logger.log(`${att}:${atts[att]}`); }
بازگشت
Object - ویژگیهای عنصر.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Attributes(offset)
ویژگیها را در فاصلهی کاراکتری مشخصشده بازیابی میکند.
نتیجه، یک شیء حاوی یک ویژگی برای هر ویژگی متنی معتبر است که در آن هر نام ویژگی با یک آیتم در شمارش Document App.Attribute مطابقت دارد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Declares style attributes. const style = {}; style[DocumentApp.Attribute.BOLD] = true; style[DocumentApp.Attribute.ITALIC] = true; style[DocumentApp.Attribute.FONT_SIZE] = 29; // Sets the style attributes to the tab's body. const text = body.editAsText(); text.setAttributes(style); // Gets the style attributes applied to the eleventh character in the // body and logs them to the console. const attributes = text.getAttributes(10); console.log(attributes);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
offset | Integer | جبران شخصیت. |
بازگشت
Object - ویژگیهای عنصر.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Background Color()
تنظیمات رنگ پسزمینه را بازیابی میکند.
بازگشت
String|null — رنگ پسزمینه، که با نمادگذاری CSS قالببندی شده است (مانند '#ffffff' )، یا null اگر عنصر شامل چندین مقدار برای این ویژگی باشد.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Background Color(offset)
رنگ پسزمینه را در فاصلهی کاراکتری مشخصشده بازیابی میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the background color of the first 3 characters in the body. const text = body.editAsText().setBackgroundColor(0, 2, '#FFC0CB'); // Gets the background color of the first character in the body. const backgroundColor = text.getBackgroundColor(0); // Logs the background color to the console. console.log(backgroundColor);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
offset | Integer | جبران شخصیت. |
بازگشت
String|null — رنگ پسزمینه، که با نمادگذاری CSS قالببندی شده است (مانند '#ffffff' ).
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Font Family()
تنظیمات خانواده فونت را بازیابی میکند. نام میتواند هر فونتی از منوی فونت در Docs یا Google Fonts باشد و به حروف کوچک و بزرگ حساس است. متدهای get Font Family() و set Font Family(fontFamilyName) اکنون به جای از نامهای رشتهای برای فونتها استفاده میکنند. اگرچه این enum منسوخ شده است، اما برای سازگاری با اسکریپتهای قدیمیتر در دسترس خواهد بود.Font Family
بازگشت
String|null — خانواده فونت، یا null اگر عنصر شامل چندین مقدار برای این ویژگی باشد.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Font Family(offset)
خانواده فونت را در فاصله کاراکتر مشخص شده بازیابی میکند. نام میتواند هر فونتی از منوی Font در Docs یا Google Fonts باشد و به حروف کوچک و بزرگ حساس است. متدهای get Font Family() و set Font Family(fontFamilyName) اکنون به جای از نامهای رشتهای برای فونتها استفاده میکنند. اگرچه این enum منسوخ شده است، اما برای سازگاری با اسکریپتهای قدیمیتر در دسترس خواهد بود.Font Family
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the font of the first 16 characters to Impact. const text = body.editAsText().setFontFamily(0, 15, 'Impact'); // Gets the font family of the 16th character in the tab body. const fontFamily = text.getFontFamily(15); // Logs the font family to the console. console.log(fontFamily);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
offset | Integer | جبران شخصیت. |
بازگشت
String|null — خانواده فونت.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Font Size()
تنظیم اندازه فونت را بازیابی میکند.
بازگشت
Number|null — اندازه فونت، یا اگر عنصر شامل چندین مقدار برای این ویژگی باشد، null.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Font Size(offset)
اندازه فونت را در فاصله کاراکتری مشخص شده بازیابی میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the font size of the first 13 characters to 15. const text = body.editAsText().setFontSize(0, 12, 15); // Gets the font size of the first character. const fontSize = text.getFontSize(0); // Logs the font size to the console. console.log(fontSize);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
offset | Integer | جبران شخصیت. |
بازگشت
Number|null — اندازه فونت.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Foreground Color()
تنظیمات رنگ پیشزمینه را بازیابی میکند.
بازگشت
String|null — رنگ پیشزمینه، که با نمادگذاری CSS قالببندی شده است (مانند '#ffffff' )، یا null اگر عنصر شامل چندین مقدار برای این ویژگی باشد.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Foreground Color(offset)
رنگ پیشزمینه را در فاصلهی کاراکتری مشخصشده بازیابی میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the foreground color of the first 3 characters in the tab body. const text = body.editAsText().setForegroundColor(0, 2, '#0000FF'); // Gets the foreground color of the first character in the tab body. const foregroundColor = text.getForegroundColor(0); // Logs the foreground color to the console. console.log(foregroundColor);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
offset | Integer | جبران شخصیت. |
بازگشت
String|null — رنگ پیشزمینه، که با نمادگذاری CSS قالببندی شده است (مانند '#ffffff' ).
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Link Url()
آدرس لینک را بازیابی میکند.
بازگشت
String|null — آدرس اینترنتی لینک، یا null اگر عنصر شامل چندین مقدار برای این ویژگی باشد.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Link Url(offset)
آدرس اینترنتی (URL) لینک را در فاصلهی کاراکتری مشخص شده بازیابی میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Applies a link to the first 10 characters in the body. const text = body.editAsText().setLinkUrl(0, 9, 'https://www.example.com/'); // Gets the URL of the link from the first character. const link = text.getLinkUrl(0); // Logs the link URL to the console. console.log(link);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
offset | Integer | جبران شخصیت. |
بازگشت
String|null — آدرس اینترنتی لینک.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Next Sibling()
عنصر خواهر یا برادر بعدی عنصر را بازیابی میکند.
خواهر یا برادر بعدی، والد یکسانی دارد و عنصر فعلی را دنبال میکند.
بازگشت
Element |null — عنصر خواهر یا برادر بعدی.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Parent()
عنصر والد عنصر را بازیابی میکند.
عنصر والد شامل عنصر فعلی است.
بازگشت
Container Element |null — عنصر والد.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Previous Sibling()
عنصر خواهر و برادر قبلی عنصر را بازیابی میکند.
عنصر خواهر یا برادر قبلی، والد یکسانی دارد و قبل از عنصر فعلی قرار میگیرد.
بازگشت
Element |null — عنصر خواهر یا برادر قبلی.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Text()
محتوای عنصر را به صورت یک رشته متنی بازیابی میکند.
بازگشت
String - محتویات عنصر به صورت رشته متنی
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Text Alignment()
ترازبندی متن را دریافت میکند. انواع ترازبندی موجود عبارتند از Document App.TextAlignment.NORMAL ، Document App.TextAlignment.SUBSCRIPT و Document App.TextAlignment.SUPERSCRIPT .
بازگشت
Text Alignment |null — نوع ترازبندی متن، یا اگر متن شامل چندین نوع ترازبندی متن باشد یا ترازبندی متن هرگز تنظیم نشده باشد، null
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Text Alignment(offset)
ترازبندی متن را برای یک کاراکتر واحد برمیگرداند. انواع ترازبندی موجود عبارتند از Document App.TextAlignment.NORMAL ، Document App.TextAlignment.SUBSCRIPT و Document App.TextAlignment.SUPERSCRIPT .
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the text alignment of the tab's body to NORMAL. const text = body.editAsText().setTextAlignment(DocumentApp.TextAlignment.NORMAL); // Gets the text alignment of the ninth character. const alignment = text.getTextAlignment(8); // Logs the text alignment to the console. console.log(alignment.toString());
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
offset | Integer | انحراف شخصیت. |
بازگشت
Text Alignment |null — نوع ترازبندی متن، یا اگر ترازبندی متن هرگز تنظیم نشده باشد، null .
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Text Attribute Indices()
مجموعهای از اندیسهای متن را که مربوط به شروع اجرای قالببندی متن متمایز هستند، بازیابی میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the text indices at which text formatting changes. const indices = body.editAsText().getTextAttributeIndices(); // Logs the indices to the console. console.log(indices.toString());
بازگشت
Integer[] — مجموعهای از اندیسهای متن که قالببندی متن در آنها تغییر میکند.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Type()
Element Type را بازیابی میکند.
برای تعیین نوع دقیق یک عنصر داده شده، get Type() استفاده کنید.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Obtain the first element in the active tab's body. const firstChild = body.getChild(0); // Use getType() to determine the element's type. if (firstChild.getType() === DocumentApp.ElementType.PARAGRAPH) { Logger.log('The first element is a paragraph.'); } else { Logger.log('The first element is not a paragraph.'); }
بازگشت
Element Type - نوع عنصر.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
insert Text(offset, text)
متن مشخص شده را در فاصلهی کاراکتری داده شده درج میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Inserts the text, 'Sample inserted text', at the start of the body content. const text = body.editAsText().insertText(0, 'Sample inserted text');
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
offset | Integer | فاصلهی کاراکتری که متن در آن درج میشود. |
text | String | متنی که قرار است درج شود. |
بازگشت
Text - عنصر فعلی.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
is At Document End()
تعیین میکند که آیا عنصر در انتهای Document قرار دارد یا خیر.
بازگشت
Boolean - اینکه آیا عنصر در انتهای تب قرار دارد یا خیر.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
is Bold()
تنظیمات پررنگ را بازیابی میکند.
بازگشت
Boolean|null — آیا متن پررنگ است یا اگر عنصر شامل چندین مقدار برای این ویژگی باشد، تهی میشود.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
is Bold(offset)
تنظیمات پررنگ را در فاصلهی کاراکتر مشخصشده بازیابی میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Bolds the first 4 characters in the tab body. const text = body.editAsText().setBold(0, 3, true); // Gets whether or not the text is bold. const bold = text.editAsText().isBold(0); // Logs the text's bold setting to the console console.log(bold);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
offset | Integer | جبران شخصیت. |
بازگشت
Boolean|null — تنظیمات پررنگ.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
is Italic()
تنظیمات ایتالیک را بازیابی میکند.
بازگشت
Boolean|null — آیا متن ایتالیک است یا اگر عنصر شامل چندین مقدار برای این ویژگی باشد، تهی میشود.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
is Italic(offset)
تنظیمات ایتالیک را در فاصلهی کاراکتری مشخصشده بازیابی میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the first 13 characters of the tab body to italic. const text = body.editAsText().setItalic(0, 12, true); // Gets whether the fifth character in the tab body is set to // italic and logs it to the console. const italic = text.isItalic(4); console.log(italic);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
offset | Integer | جبران شخصیت. |
بازگشت
Boolean|null — تنظیم ایتالیک.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
is Strikethrough()
تنظیمات خط خورده را بازیابی میکند.
بازگشت
Boolean|null — آیا متن خط خورده است یا اگر عنصر شامل چندین مقدار برای این ویژگی باشد، تهی است
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
is Strikethrough(offset)
تنظیمات خطخوردگی را در فاصلهی کاراکتری مشخصشده بازیابی میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the first 17 characters of the tab body to strikethrough. const text = body.editAsText().setStrikethrough(0, 16, true); // Gets whether the first character in the tab body is set to // strikethrough and logs it to the console. const strikethrough = text.isStrikethrough(0); console.log(strikethrough);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
offset | Integer | جبران شخصیت. |
بازگشت
Boolean|null — تنظیم خط خورده.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
is Underline()
تنظیمات زیرخط را بازیابی میکند.
بازگشت
Boolean|null — آیا متن زیرخطدار است یا اگر عنصر شامل چندین مقدار برای این ویژگی باشد، تهی میشود.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
is Underline(offset)
تنظیمات زیرخط را در فاصلهی کاراکتری مشخصشده بازیابی میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the first 13 characters of the tab body to underline. const text = body.editAsText().setUnderline(0, 12, false); // Gets whether the first character in the tab body is set to // underline and logs it to the console const underline = text.editAsText().isUnderline(0); console.log(underline);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
offset | Integer | جبران شخصیت. |
بازگشت
Boolean|null — تنظیم زیرخط.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
merge()
عنصر را با عنصر خواهر یا برادر قبلی از همان نوع ادغام میکند.
فقط عناصری که از Element Type یکسانی هستند میتوانند ادغام شوند. هر عنصر فرزندی که در عنصر فعلی قرار داشته باشد، به عنصر خواهر و برادر قبلی منتقل میشود.
عنصر فعلی از سند حذف میشود.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Example 1: Merge paragraphs // Append two paragraphs to the document's active tab. const par1 = body.appendParagraph('Paragraph 1.'); const par2 = body.appendParagraph('Paragraph 2.'); // Merge the newly added paragraphs into a single paragraph. par2.merge(); // Example 2: Merge table cells // Create a two-dimensional array containing the table's cell contents. const cells = [ ['Row 1, Cell 1', 'Row 1, Cell 2'], ['Row 2, Cell 1', 'Row 2, Cell 2'], ]; // Build a table from the array. const table = body.appendTable(cells); // Get the first row in the table. const row = table.getRow(0); // Get the two cells in this row. const cell1 = row.getCell(0); const cell2 = row.getCell(1); // Merge the current cell into its preceding sibling element. const merged = cell2.merge();
بازگشت
Text |null — عنصر ادغامشده.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
remove From Parent()
عنصر را از والدش حذف میکند.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Remove all images in the active tab's body. const imgs = body.getImages(); for (let i = 0; i < imgs.length; i++) { imgs[i].removeFromParent(); }
بازگشت
Text |null — عنصر حذف شده.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
replace Text(searchPattern, replacement)
با استفاده از عبارات منظم، تمام موارد تکرار یک الگوی متنی مشخص را با یک رشته جایگزین مشخص جایگزین میکند.
الگوی جستجو به صورت یک رشته ارسال میشود، نه یک شیء عبارت منظم جاوا اسکریپت. به همین دلیل، باید هرگونه بکاسلش را در الگو escape کنید.
این روش از کتابخانه عبارات منظم RE2 گوگل استفاده میکند که سینتکسهای پشتیبانیشده را محدود میکند.
الگوی عبارت منظم ارائه شده به طور مستقل با هر بلوک متنی موجود در عنصر فعلی مطابقت داده میشود.
const body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody(); // Clear the text surrounding "Apps Script", with or without text. body.replaceText('^.*Apps ?Script.*$', 'Apps Script');
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
search Pattern | String | الگوی regex برای جستجو |
replacement | String | متنی که قرار است به عنوان جایگزین استفاده شود |
بازگشت
Element - عنصر فعلی
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Attributes(startOffset, endOffsetInclusive, attributes)
ویژگیهای مشخصشده را به محدوده کاراکتر دادهشده اعمال میکند.
پارامتر ویژگیهای مشخصشده باید یک شیء باشد که در آن نام هر ویژگی، یک آیتم در شمارش Document App.Attribute است و مقدار هر ویژگی، مقدار جدیدی است که باید اعمال شود.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Declares style attributes for font size and font family. const style = {}; style[DocumentApp.Attribute.FONT_SIZE] = 20; style[DocumentApp.Attribute.FONT_FAMILY] = 'Impact'; // Sets the style attributes to the first 9 characters in the tab's body. const text = body.setAttributes(0, 8, style);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
start Offset | Integer | آفست شروع محدوده متن. |
end Offset Inclusive | Integer | آفست انتهایی محدودهی متن. |
attributes | Object | ویژگیهای عنصر. |
بازگشت
Text - عنصر فعلی.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Attributes(attributes)
ویژگیهای عنصر را تنظیم میکند.
پارامتر ویژگیهای مشخصشده باید یک شیء باشد که در آن نام هر ویژگی، یک آیتم در شمارش Document App.Attribute است و مقدار هر ویژگی، مقدار جدیدی است که باید اعمال شود.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Define a custom paragraph style. const style = {}; style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.RIGHT; style[DocumentApp.Attribute.FONT_FAMILY] = 'Calibri'; style[DocumentApp.Attribute.FONT_SIZE] = 18; style[DocumentApp.Attribute.BOLD] = true; // Append a plain paragraph. const par = body.appendParagraph('A paragraph with custom style.'); // Apply the custom style. par.setAttributes(style);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
attributes | Object | ویژگیهای عنصر. |
بازگشت
Text - عنصر فعلی.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Background Color(startOffset, endOffsetInclusive, color)
رنگ پسزمینه را برای محدوده کاراکتر مشخص شده تنظیم میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the background color of the first 3 characters in the // tab body to hex color #0000FF. const text = body.editAsText().setBackgroundColor(0, 2, '#0000FF');
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
start Offset | Integer | آفست شروع محدوده متن. |
end Offset Inclusive | Integer | آفست انتهایی محدودهی متن. |
color | String | رنگ پسزمینه، که با نمادگذاری CSS قالببندی شده است (مانند '#ffffff' ). |
بازگشت
Text - عنصر فعلی.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Background Color(color)
رنگ پس زمینه را تنظیم میکند.
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
color | String | رنگ پسزمینه، که با نمادگذاری CSS قالببندی شده است (مانند '#ffffff' ) |
بازگشت
Text - عنصر فعلی
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Bold(bold)
تنظیمات پررنگ را تنظیم میکند.
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
bold | Boolean | تنظیمات جسورانه |
بازگشت
Text - عنصر فعلی
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Bold(startOffset, endOffsetInclusive, bold)
تنظیمات پررنگ بودن را برای محدوده کاراکتر مشخص شده تنظیم میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the first 11 characters in the tab's body to bold. const text = body.editAsText().setBold(0, 10, true);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
start Offset | Integer | آفست شروع محدوده متن. |
end Offset Inclusive | Integer | آفست انتهایی محدودهی متن. |
bold | Boolean | محیط جسورانه. |
بازگشت
Text - عنصر فعلی.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Font Family(startOffset, endOffsetInclusive, fontFamilyName)
خانواده فونت را برای محدوده کاراکتر مشخص شده تنظیم میکند. نام میتواند هر فونتی از منوی Font در Docs یا Google Fonts باشد و به حروف کوچک و بزرگ حساس است. نام فونتهای ناشناخته به صورت Arial رندر میشوند. متدهای get Font Family(offset) و set Font Family(fontFamilyName) اکنون به جای از نامهای رشتهای برای فونتها استفاده میکنند. اگرچه این enum منسوخ شده است، اما برای سازگاری با اسکریپتهای قدیمیتر در دسترس خواهد بود. Font Family
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the font of the first 4 characters in the tab's body to Roboto. const text = body.editAsText().setFontFamily(0, 3, 'Roboto');
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
start Offset | Integer | آفست شروع محدوده متن. |
end Offset Inclusive | Integer | آفست انتهایی محدودهی متن. |
font Family Name | String | نام خانواده فونت، از منوی فونت در سندنگار یا فونتهای گوگل. |
بازگشت
Text - عنصر فعلی.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Font Family(fontFamilyName)
خانواده فونت را تنظیم میکند. نام میتواند هر فونتی از منوی Font در Docs یا Google Fonts باشد و به حروف کوچک و بزرگ حساس است. نام فونتهای ناشناخته به صورت Arial رندر میشوند. متدهای get Font Family() و set Font Family(fontFamilyName) اکنون به جای از نامهای رشتهای برای فونتها استفاده میکنند. اگرچه این enum منسوخ شده است، اما برای سازگاری با اسکریپتهای قدیمیتر در دسترس خواهد بود.Font Family
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
font Family Name | String | نام خانواده فونت، از منوی فونت در Docs یا فونتهای گوگل |
بازگشت
Text - عنصر فعلی
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Font Size(startOffset, endOffsetInclusive, size)
اندازه فونت را برای محدوده کاراکتر مشخص شده تنظیم میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the size of the first 11 characters in the tab's body to 12. const text = body.editAsText().setFontSize(0, 10, 12);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
start Offset | Integer | آفست شروع محدوده متن. |
end Offset Inclusive | Integer | آفست انتهایی محدودهی متن. |
size | Number | اندازه فونت. |
بازگشت
Text - عنصر فعلی.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Font Size(size)
اندازه فونت را تنظیم میکند.
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
size | Number | اندازه فونت |
بازگشت
Text - عنصر فعلی
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Foreground Color(startOffset, endOffsetInclusive, color)
رنگ پیشزمینه را برای محدوده کاراکتر مشخص شده تنظیم میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the foreground color of the first 2 characters in the // tab's body to hex color #FF0000. const text = body.editAsText().setForegroundColor(0, 1, '#FF0000'); // Gets the foreground color for the second character in the tab's body. const foregroundColor = text.getForegroundColor(1); // Logs the foreground color to the console. console.log(foregroundColor);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
start Offset | Integer | آفست شروع محدوده متن. |
end Offset Inclusive | Integer | آفست انتهایی محدودهی متن. |
color | String | رنگ پیشزمینه، که با نمادگذاری CSS قالببندی شده است (مانند '#ffffff' ). |
بازگشت
Text - عنصر فعلی.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Foreground Color(color)
رنگ پیشزمینه را تنظیم میکند.
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
color | String | رنگ پیشزمینه، که با نمادگذاری CSS قالببندی شده است (مانند '#ffffff' ) |
بازگشت
Text - عنصر فعلی
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Italic(italic)
حالت ایتالیک را تنظیم میکند.
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
italic | Boolean | تنظیمات ایتالیک |
بازگشت
Text - عنصر فعلی
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Italic(startOffset, endOffsetInclusive, italic)
تنظیمات ایتالیک را برای محدوده کاراکتر مشخص شده تنظیم میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the first 11 characters in the tab's body to italic. const text = body.editAsText().setItalic(0, 10, true);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
start Offset | Integer | آفست شروع محدوده متن. |
end Offset Inclusive | Integer | آفست انتهایی محدودهی متن. |
italic | Boolean | تنظیم ایتالیک. |
بازگشت
Text - عنصر فعلی.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Link Url(startOffset, endOffsetInclusive, url)
آدرس اینترنتی (URL) لینک را برای محدوده کاراکتری مشخص شده تنظیم میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Applies a link to the first 11 characters in the body. const text = body.editAsText().setLinkUrl(0, 10, 'https://example.com');
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
start Offset | Integer | آفست شروع محدوده متن. |
end Offset Inclusive | Integer | آفست انتهایی محدودهی متن. |
url | String | آدرس اینترنتی (URL) لینک. |
بازگشت
Text - عنصر فعلی.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Link Url(url)
set Strikethrough(strikethrough)
تنظیمات خط خورده را تنظیم میکند.
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
strikethrough | Boolean | تنظیمات خط خورده |
بازگشت
Text - عنصر فعلی
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Strikethrough(startOffset, endOffsetInclusive, strikethrough)
تنظیمات خطخوردگی را برای محدوده کاراکتر مشخصشده تنظیم میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the first 11 characters in the tab's body to strikethrough. const text = body.editAsText().setStrikethrough(0, 10, true);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
start Offset | Integer | آفست شروع محدوده متن. |
end Offset Inclusive | Integer | آفست انتهایی محدودهی متن. |
strikethrough | Boolean | تنظیمات خط خورده. |
بازگشت
Text - عنصر فعلی.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Text(text)
محتوای متن را تنظیم میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Replaces the contents of the body with the text, 'New body text.' const text = body.editAsText().setText('New body text.');
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
text | String | محتوای متن جدید. |
بازگشت
Text - عنصر فعلی.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Text Alignment(startOffset, endOffsetInclusive, textAlignment)
ترازبندی متن را برای یک محدوده کاراکتری مشخص تنظیم میکند. انواع ترازبندی موجود عبارتند از Document App.TextAlignment.NORMAL ، Document App.TextAlignment.SUBSCRIPT و Document App.TextAlignment.SUPERSCRIPT .
// Make the first character in the first paragraph of the active tab be // superscript. const documentTab = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab(); const text = documentTab.getBody().getParagraphs()[0].editAsText(); text.setTextAlignment(0, 0, DocumentApp.TextAlignment.SUPERSCRIPT);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
start Offset | Integer | فاصلهی شروع محدودهی کاراکترها. |
end Offset Inclusive | Integer | آفست انتهایی محدوده کاراکتر (شامل). |
text Alignment | Text Alignment | نوع ترازبندی متن که باید اعمال شود. |
بازگشت
Text - عنصر فعلی.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Text Alignment(textAlignment)
ترازبندی متن را تنظیم میکند. انواع ترازبندی موجود عبارتند از Document App.TextAlignment.NORMAL ، Document App.TextAlignment.SUBSCRIPT و Document App.TextAlignment.SUPERSCRIPT .
// Make the entire first paragraph in the active tab be superscript. const documentTab = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab(); const text = documentTab.getBody().getParagraphs()[0].editAsText(); text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
text Alignment | Text Alignment | نوع ترازبندی متن که باید اعمال شود |
بازگشت
Text - عنصر فعلی
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Underline(underline)
تنظیمات زیرخط را تنظیم میکند.
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
underline | Boolean | تنظیمات زیر خط |
بازگشت
Text - عنصر فعلی
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Underline(startOffset, endOffsetInclusive, underline)
تنظیمات زیرخط را برای محدوده کاراکتر مشخص شده تنظیم میکند.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the first 11 characters in the tab's body to underline. const text = body.editAsText().setUnderline(0, 10, true);
پارامترها
| نام | نوع | توضیحات |
|---|---|---|
start Offset | Integer | آفست شروع محدوده متن. |
end Offset Inclusive | Integer | آفست انتهایی محدودهی متن. |
underline | Boolean | تنظیمات زیرخط. |
بازگشت
Text - عنصر فعلی.
مجوز
اسکریپتهایی که از این روش استفاده میکنند، نیاز به مجوز با یک یا چند مورد از حوزههای زیر دارند:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents