عنصر يمثّل منطقة نص منسق يتم تضمين كل النص في Document
ضمن عناصر Text
.
يمكن أن يكون عنصر Text
مضمّنًا في Equation
أو Equation
أو
List
أو Paragraph
، ولكن لا يمكن أن يحتوي على أي عنصر آخر. لمزيد من
المعلومات حول بنية المستند، يُرجى الاطّلاع على دليل توسيع نطاق "مستندات Google".
// 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 | تُضيف هذه الدالة النص المحدّد إلى نهاية منطقة النص هذه. |
copy() | Text | تعرِض نسخة مفصَّلة ومُفصَّلة من العنصر الحالي. |
delete | Text | لحذف نطاق نص |
edit | Text | الحصول على نسخة Text من العنصر الحالي لتعديلها |
find | Range | تبحث في محتوى العنصر عن النمط النصي المحدّد باستخدام التعبيرات العادية. |
find | Range | البحث في محتوى العنصر عن نمط النص المحدّد، بدءًا من نتيجة بحث معيّنة |
get | Object | يسترجع سمات العنصر. |
get | Object | يسترجع السمات في الإزاحة المحدّدة للحرف. |
get | String | يسترجع إعداد لون الخلفية. |
get | String | يسترجع لون الخلفية عند بدء الحرف المحدّد. |
get | String | يسترجع إعدادات مجموعة الخطوط. |
get | String | يسترجع مجموعة الخطوط عند بدء الحرف المحدّد. |
get | Number | استرداد إعداد حجم الخط |
get | Number | يسترجع حجم الخط عند إزاحة الحرف المحدّدة. |
get | String | استرداد إعداد لون المقدّمة |
get | String | يسترجع لون المقدّمة عند إزاحة الحرف المحدّدة. |
get | String | يستردّ عنوان URL للرابط. |
get | String | يسترجع عنوان URL للرابط عند بدء الحرف المحدّد. |
get | Element | يسترجع العنصر الشقيق التالي للعنصر. |
get | Container | يسترجع العنصر الرئيسي للعنصر. |
get | Element | يسترجع العنصر الشقيق السابق للعنصر. |
get | String | يسترجع محتوى العنصر كسلسلة نصية. |
get | Text | الحصول على محاذاة النص |
get | Text | تحصل على محاذاة النص لحرف واحد. |
get | Integer[] | يسترجع مجموعة فهارس النصوص التي تتوافق مع بداية عمليات تنفيذ تنسيقات مختلفة للنصوص. |
get | Element | يسترجع Element للعنصر. |
insert | Text | تُدرج هذه الدالة النص المحدّد في الإزاحة المحدّدة للحرف. |
is | Boolean | لتحديد ما إذا كان العنصر في نهاية Document |
is | Boolean | يستردّ إعداد الكتابة بخط عريض. |
is | Boolean | يسترجع الإعداد المخصّص للنص المميّز بالخطّ العريض عند إزاحة الحرف المحدّدة. |
is | Boolean | يستردّ إعداد النص المائل. |
is | Boolean | يسترجع الإعداد المائل في الإزاحة المحدّدة للحرف. |
is | Boolean | يستردّ إعداد تمييز النص بخط مُمَحَّى. |
is | Boolean | يسترجع إعداد تمييز النص بخط مُمَحَّى في الإزاحة المحدّدة للحرف. |
is | Boolean | يستردّ إعداد التأكيد. |
is | Boolean | يسترجع إعداد ال underline في الإزاحة المحدّدة للحرف. |
merge() | Text | دمج العنصر مع العنصر الشقيق السابق من النوع نفسه |
remove | Text | تزيل العنصر من العنصر الرئيسي. |
replace | Element | لاستبدال جميع مظاهر نمط نصي معيّن بسلسلة بديل معيّنة، باستخدام تعبيرات عادية. |
set | Text | تطبِّق السمات المحدّدة على نطاق الأحرف المحدّد. |
set | Text | تُستخدَم لضبط سمات العنصر. |
set | Text | لضبط لون الخلفية لنطاق الأحرف المحدّد |
set | Text | لضبط لون الخلفية. |
set | Text | لضبط الإعداد "غامق" |
set | Text | تضبط هذه السمة النصّ بخط عريض لنطاق الأحرف المحدّد. |
set | Text | لضبط مجموعة الخطوط لمجموعة الأحرف المحدّدة |
set | Text | لضبط مجموعة الخطوط |
set | Text | لضبط حجم الخط لنطاق الأحرف المحدّد |
set | Text | لضبط حجم الخط |
set | Text | لضبط لون المقدّمة لنطاق الأحرف المحدّد |
set | Text | لضبط لون المقدّمة. |
set | Text | لضبط النص المائل |
set | Text | تضبط هذه السمة النص المائل لنطاق الأحرف المحدّد. |
set | Text | تُحدِّد عنوان URL للرابط لنطاق الأحرف المحدَّد. |
set | Text | لضبط عنوان URL للرابط |
set | Text | لضبط إعدادات وضع شرطة مُموَّهة |
set | Text | لضبط إعدادات وضع شرطة مُموَّهة لنطاق الأحرف المحدّد |
set | Text | لضبط محتوى النص |
set | Text | لضبط محاذاة النص لنطاق أحرف معيّن. |
set | Text | لضبط محاذاة النص |
set | Text | لضبط إعدادات الخطوط السفلية |
set | Text | لضبط إعدادات ال underline لنطاق الأحرف المحدّد |
مستندات تفصيلية
appendText(text)
تُضيف هذه الدالة النص المحدّد إلى نهاية منطقة النص هذه.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Adds the text, 'Sample body text,' to the end of the tab body. const text = body.editAsText().appendText('Sample body text');
المعلمات
الاسم | النوع | الوصف |
---|---|---|
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/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 | Integer | إزاحة الحرف لأول حرف تريد حذفه. |
end | Integer | فهرس الحرف الأخير المطلوب حذفه |
الإرجاع
Text
: العنصر الحالي
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
editAsText()
الحصول على نسخة Text
من العنصر الحالي لتعديلها
استخدِم edit
لتعديل محتوى العناصر كنص منسق. يتجاهل وضع edit
العناصر غير النصية (مثل Inline
وHorizontal
).
تتم إزالة العناصر الفرعية المضمّنة بالكامل ضمن نطاق نص تم حذفه من العنصر.
const body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody(); // Insert two paragraphs separated by a paragraph containing an // horizontal rule. body.insertParagraph(0, 'An editAsText sample.'); body.insertHorizontalRule(0); body.insertParagraph(0, 'An example.'); // Delete " sample.\n\n An" removing the horizontal rule in the process. body.editAsText().deleteText(14, 25);
الإرجاع
Text
: نسخة نصية للعنصر الحالي
findText(searchPattern)
تبحث في محتوى العنصر عن النمط النصي المحدّد باستخدام التعبيرات العادية.
لا تتوفّر مجموعة فرعية من ميزات التعبير العادي في JavaScript بالكامل، مثل مجموعات الالتقاط وعوامل تعديل الوضع.
تتم مطابقة نمط التعبير العادي المقدَّم بشكل مستقل مع كلّ كتلة نص مضمّنة في العنصر الحالي.
المعلمات
الاسم | النوع | الوصف |
---|---|---|
search | String | النمط المطلوب البحث عنه |
الإرجاع
Range
: نتيجة بحث تشير إلى موضع نص البحث، أو قيمة فارغة في حال عدم توفّر
مطابقة
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
findText(searchPattern, from)
البحث في محتوى العنصر عن نمط النص المحدّد، بدءًا من نتيجة بحث معيّنة
لا تتوفّر مجموعة فرعية من ميزات التعبير العادي في JavaScript بالكامل، مثل مجموعات الالتقاط وعوامل تعديل الوضع.
تتم مطابقة نمط التعبير العادي المقدَّم بشكل مستقل مع كلّ كتلة نص مضمّنة في العنصر الحالي.
المعلمات
الاسم | النوع | الوصف |
---|---|---|
search | String | النمط المطلوب البحث عنه |
from | Range | نتيجة البحث التي تريد البحث منها |
الإرجاع
Range
: نتيجة بحث تشير إلى الموضع التالي لنص البحث، أو قيمة فارغة في حال عدم توفّر مطابقة
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getAttributes()
يسترجع سمات العنصر.
والنتيجة هي عنصر يحتوي على سمة لكل سمة عنصر صالحة، حيث يتوافق كل اسم
سمة مع عنصر في التعداد Document
.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Append a styled paragraph. const par = body.appendParagraph('A bold, italicized paragraph.'); par.setBold(true); par.setItalic(true); // Retrieve the paragraph's attributes. const atts = par.getAttributes(); // Log the paragraph attributes. for (const att in atts) { Logger.log(`${att}:${atts[att]}`); }
الإرجاع
Object
: سمات العنصر
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getAttributes(offset)
يسترجع السمات في الإزاحة المحدّدة للحرف.
والنتيجة هي عنصر يحتوي على سمة لكل سمة نصية صالحة حيث يتوافق كل اسم
سمة مع عنصر في التعداد Document
.
// 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
getBackgroundColor()
يسترجع إعداد لون الخلفية.
الإرجاع
String
: لون الخلفية منسَّقًا بترميز CSS (مثل '#ffffff'
)، أو null
إذا كان العنصر يحتوي على قيم متعدّدة لهذه السمة
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getBackgroundColor(offset)
يسترجع لون الخلفية عند بدء الحرف المحدّد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('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
: لون الخلفية بتنسيق صفحات الأنماط المتتالية (CSS) (مثل '#ffffff'
)
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getFontFamily()
يسترجع إعدادات مجموعة الخطوط. يمكن أن يكون الاسم أي خط من قائمة "الخط" في "مستندات Google" أو Google Fonts، ويكون حسّاسًا لحالة الأحرف. تستخدم الطريقتان get
وset
الآن أسماء سلاسل للخطوط بدلاً من
التعداد الإجمالي
. على الرغم من أنّه تم
إيقاف هذا التصنيف نهائيًا، سيظل متاحًا للتوافق مع النصوص البرمجية القديمة.Font
الإرجاع
String
: عائلة الخط، أو قيمة فارغة إذا كان العنصر يحتوي على قيم متعددة لهذه السمة
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getFontFamily(offset)
يسترجع مجموعة الخطوط عند بدء الحرف المحدّد. يمكن أن يكون الاسم أي خط من قائمة
الخطوط في "مستندات Google" أو Google Fonts، ويكون حساسًا
لحالة الأحرف. تستخدم الطريقتان get
وset
الآن أسماء سلاسل للخطوط بدلاً من التعداد
. على الرغم من أنّه تم
إيقاف هذا التصنيف نهائيًا، سيظل متاحًا للتوافق مع النصوص البرمجية القديمة.
Font
// 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
: مجموعة الخطوط
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getFontSize()
استرداد إعداد حجم الخط
الإرجاع
Number
: حجم الخط، أو قيمة فارغة إذا كان العنصر يحتوي على قيم متعدّدة لهذه السمة
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getFontSize(offset)
يسترجع حجم الخط عند إزاحة الحرف المحدّدة.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the font size of the first 13 characters to 15. const text = body.editAsText().setFontSize(0, 12, 15); // Gets the font size of the first character. const fontSize = text.getFontSize(0); // Logs the font size to the console. console.log(fontSize);
المعلمات
الاسم | النوع | الوصف |
---|---|---|
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/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
: لون المقدّمة بتنسيق صفحات الأنماط المتتالية (CSS) (مثل '#ffffff'
)
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getLinkUrl()
يستردّ عنوان URL للرابط.
الإرجاع
String
: عنوان URL للرابط، أو قيمة فارغة إذا كان العنصر يحتوي على قيم متعددة لهذه السمة
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getLinkUrl(offset)
يسترجع عنوان URL للرابط عند بدء الحرف المحدّد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Applies a link to the first 10 characters in the body. const text = body.editAsText().setLinkUrl(0, 9, 'https://www.example.com/'); // Gets the URL of the link from the first character. const link = text.getLinkUrl(0); // Logs the link URL to the console. console.log(link);
المعلمات
الاسم | النوع | الوصف |
---|---|---|
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()
يسترجع العنصر الرئيسي للعنصر.
يحتوي العنصر الرئيسي على العنصر الحالي.
الإرجاع
Container
: العنصر الرئيسي
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
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()
الحصول على محاذاة النص الأنواع المتاحة للمحاذاة هي Document
وDocument
وDocument
.
الإرجاع
Text
: نوع محاذاة النص، أو null
إذا كان النص يحتوي على أنواع متعدّدة من محاذاة
النص أو إذا لم يتم ضبط محاذاة النص مطلقًا
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getTextAlignment(offset)
تحصل على محاذاة النص لحرف واحد. الأنواع المتاحة للمحاذاة هي Document
وDocument
وDocument
.
// 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
: نوع محاذاة النص، أو null
إذا لم يتم ضبط محاذاة النص مطلقًا
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getTextAttributeIndices()
يسترجع مجموعة فهارس النصوص التي تتوافق مع بداية عمليات تنفيذ تنسيقات مختلفة للنصوص.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the text indices at which text formatting changes. const indices = body.editAsText().getTextAttributeIndices(); // Logs the indices to the console. console.log(indices.toString());
الإرجاع
Integer[]
: مجموعة فهارس النصوص التي يتغيّر فيها تنسيق النص
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getType()
يسترجع Element
للعنصر.
استخدِم get
لتحديد النوع الدقيق لعنصر معيّن.
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
: نوع العنصر
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertText(offset, text)
تُدرج هذه الدالة النص المحدّد في الإزاحة المحدّدة للحرف.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Inserts the text, 'Sample inserted text', at the start of the body content. const text = body.editAsText().insertText(0, 'Sample inserted text');
المعلمات
الاسم | النوع | الوصف |
---|---|---|
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/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
: الإعداد المخصّص للنص الغامق
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isItalic()
يستردّ إعداد النص المائل.
الإرجاع
Boolean
: ما إذا كان النص مائلًا أو فارغًا إذا كان العنصر يحتوي على قيم متعدّدة لهذه
السمة
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isItalic(offset)
يسترجع الإعداد المائل في الإزاحة المحدّدة للحرف.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('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
: إعداد النص المائل
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isStrikethrough()
يستردّ إعداد تمييز النص بخط مُمَحَّى.
الإرجاع
Boolean
: ما إذا كان النص مشطوبًا أو فارغًا إذا كان العنصر يحتوي على قيم متعدّدة لهذه السمة
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isStrikethrough(offset)
يسترجع إعداد تمييز النص بخط مُمَحَّى في الإزاحة المحدّدة للحرف.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('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
: إعداد النص المشطوب
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isUnderline()
يستردّ إعداد التأكيد.
الإرجاع
Boolean
: ما إذا كان النص مُخطَّطًا أو فارغًا إذا كان العنصر يحتوي على قيم متعدّدة لهذه السمة
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isUnderline(offset)
يسترجع إعداد ال 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 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
: إعداد التسطير
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
merge()
دمج العنصر مع العنصر الشقيق السابق من النوع نفسه
لا يمكن دمج سوى عناصر Element
نفسها. يتم نقل أي عناصر فرعية مضمّنة في
العنصر الحالي إلى العنصر الشقيق السابق.
تتم إزالة العنصر الحالي من المستند.
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
: العنصر المدمج
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removeFromParent()
تزيل العنصر من العنصر الرئيسي.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Remove all images in the active tab's body. const imgs = body.getImages(); for (let i = 0; i < imgs.length; i++) { imgs[i].removeFromParent(); }
الإرجاع
Text
: العنصر الذي تمّت إزالته
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
replaceText(searchPattern, replacement)
لاستبدال جميع مظاهر نمط نصي معيّن بسلسلة بديل معيّنة، باستخدام تعبيرات عادية.
يتم تمرير نمط البحث كسلسلة، وليس ككائن تعبير عادي في JavaScript. لهذا السبب، عليك إزالة أي شرطات سفلية في النمط.
تستخدِم هذه الطرق مكتبة RE2 للتعبيرات العادية من Google، ما يحدّ من البنية المتوافقة.
تتم مطابقة نمط التعبير العادي المقدَّم بشكل مستقل مع كلّ كتلة نص مضمّنة في العنصر الحالي.
const body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody(); // Clear the text surrounding "Apps Script", with or without text. body.replaceText('^.*Apps ?Script.*$', 'Apps Script');
المعلمات
الاسم | النوع | الوصف |
---|---|---|
search | String | نمط التعبير العادي المطلوب البحث عنه |
replacement | String | النص الذي سيتم استخدامه كبديل |
الإرجاع
Element
: العنصر الحالي
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setAttributes(startOffset, endOffsetInclusive, attributes)
تطبِّق السمات المحدّدة على نطاق الأحرف المحدّد.
يجب أن تكون مَعلمة السمات المحدّدة عنصرًا يكون فيه كل اسم خاصية عنصرًا في التعداد Document
وتكون كل قيمة خاصية هي القيمة الجديدة التي سيتم تطبيقها.
// 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 | Integer | إزاحة بداية نطاق النص |
end | Integer | القيمة المضافة إلى بداية نطاق النص لتحديد نهايته. |
attributes | Object | سمات العنصر |
الإرجاع
Text
: العنصر الحالي
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setAttributes(attributes)
تُستخدَم لضبط سمات العنصر.
يجب أن تكون مَعلمة السمات المحدّدة عنصرًا يكون فيه كل اسم خاصية عنصرًا في التعداد Document
وتكون كل قيمة خاصية هي القيمة الجديدة التي سيتم تطبيقها.
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
setBackgroundColor(startOffset, endOffsetInclusive, color)
لضبط لون الخلفية لنطاق الأحرف المحدّد
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the background color of the first 3 characters in the // tab body to hex color #0000FF. const text = body.editAsText().setBackgroundColor(0, 2, '#0000FF');
المعلمات
الاسم | النوع | الوصف |
---|---|---|
start | Integer | إزاحة بداية نطاق النص |
end | 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/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 | Integer | إزاحة بداية نطاق النص |
end | Integer | القيمة المضافة إلى بداية نطاق النص لتحديد نهايته. |
bold | Boolean | وضع الكتابة بخط غامق |
الإرجاع
Text
: العنصر الحالي
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setFontFamily(startOffset, endOffsetInclusive, fontFamilyName)
لضبط مجموعة الخطوط لمجموعة الأحرف المحدّدة يمكن أن يكون الاسم أي خط من قائمة "الخط"
في "مستندات Google" أو Google Fonts، ويكون حسّاسًا لحالة الأحرف.
سيتم عرض أسماء الخطوط غير المعروفة على أنّها Arial. تستخدم الطريقتان get
و
set
الآن أسماء سلاسل للخطوط بدلاً من التعداد
. على الرغم من أنّه تم
إيقاف هذا التصنيف نهائيًا، سيظل متاحًا للتوافق مع النصوص البرمجية القديمة.
Font
// 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 | Integer | إزاحة بداية نطاق النص |
end | Integer | القيمة المضافة إلى بداية نطاق النص لتحديد نهايته. |
font | String | اسم مجموعة الخطوط، من قائمة "الخط" في "مستندات Google" أو Google Fonts |
الإرجاع
Text
: العنصر الحالي
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setFontFamily(fontFamilyName)
لضبط مجموعة الخطوط يمكن أن يكون الاسم أي خط من قائمة "الخط" في "مستندات Google" أو Google Fonts، ويكون حسّاسًا لحالة الأحرف. سيتم عرض أسماء
الخطوط غير المعروفة على أنّها Arial. تستخدم الطريقتان get
وset
الآن أسماء سلاسل للخطوط بدلاً من التعداد
. على الرغم من أنّه تم
إيقاف هذا التصنيف نهائيًا، سيظل متاحًا للتوافق مع النصوص البرمجية القديمة.Font
المعلمات
الاسم | النوع | الوصف |
---|---|---|
font | String | اسم مجموعة الخطوط، من قائمة "الخط" في "مستندات Google" أو Google Fonts |
الإرجاع
Text
: العنصر الحالي
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setFontSize(startOffset, endOffsetInclusive, size)
لضبط حجم الخط لنطاق الأحرف المحدّد
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('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 | Integer | إزاحة بداية نطاق النص |
end | Integer | القيمة المضافة إلى بداية نطاق النص لتحديد نهايته. |
size | Number | حجم الخط |
الإرجاع
Text
: العنصر الحالي
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setFontSize(size)
setForegroundColor(startOffset, endOffsetInclusive, color)
لضبط لون المقدّمة لنطاق الأحرف المحدّد
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the foreground color of the first 2 characters in the // tab's body to hex color #FF0000. const text = body.editAsText().setForegroundColor(0, 1, '#FF0000'); // Gets the foreground color for the second character in the tab's body. const foregroundColor = text.getForegroundColor(1); // Logs the foreground color to the console. console.log(foregroundColor);
المعلمات
الاسم | النوع | الوصف |
---|---|---|
start | Integer | إزاحة بداية نطاق النص |
end | 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)
setItalic(startOffset, endOffsetInclusive, italic)
تضبط هذه السمة النص المائل لنطاق الأحرف المحدّد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Sets the first 11 characters in the tab's body to italic. const text = body.editAsText().setItalic(0, 10, true);
المعلمات
الاسم | النوع | الوصف |
---|---|---|
start | Integer | إزاحة بداية نطاق النص |
end | 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/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 | Integer | إزاحة بداية نطاق النص |
end | Integer | القيمة المضافة إلى بداية نطاق النص لتحديد نهايته. |
url | String | عنوان URL للرابط |
الإرجاع
Text
: العنصر الحالي
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setLinkUrl(url)
لضبط عنوان URL للرابط
المعلمات
الاسم | النوع | الوصف |
---|---|---|
url | String | عنوان URL للرابط |
الإرجاع
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/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 | Integer | إزاحة بداية نطاق النص |
end | 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/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
setTextAlignment(startOffset, endOffsetInclusive, textAlignment)
لضبط محاذاة النص لنطاق أحرف معيّن. الأنواع المتاحة للمحاذاة هي
Document
وDocument
و
Document
.
// 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 | Integer | إزاحة بداية نطاق الأحرف. |
end | Integer | القيمة المضافة إلى بداية نطاق الأحرف (شاملة) |
text | Text | نوع محاذاة النص المطلوب تطبيقها. |
الإرجاع
Text
: العنصر الحالي
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setTextAlignment(textAlignment)
لضبط محاذاة النص الأنواع المتاحة للمحاذاة هي Document
وDocument
وDocument
.
// 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 | Text | نوع محاذاة النص المطلوب تطبيقها |
الإرجاع
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)
لضبط إعدادات ال 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 | Integer | إزاحة بداية نطاق النص |
end | Integer | القيمة المضافة إلى بداية نطاق النص لتحديد نهايته. |
underline | Boolean | إعداد التسطير |
الإرجاع
Text
: العنصر الحالي
التفويض
تتطلّب النصوص البرمجية التي تستخدِم هذه الطريقة الحصول على إذن واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents