عنصر يمثّل منطقة نص منسّق يجب أن يكون كل النص في Document مضمّنًا في عناصر Text.
يمكن أن يكون العنصر Text مضمّنًا في Equation أو EquationFunction أو ListItem أو 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|null | تعرض هذه السمة إعداد لون الخلفية. |
get | String|null | تسترد لون الخلفية عند موضع الحرف المحدد. |
get | String|null | تعرض هذه السمة إعدادات مجموعة الخطوط. |
get | String|null | تسترد مجموعة الخطوط عند الإزاحة المحدّدة للأحرف. |
get | Number|null | تعرض هذه السمة إعدادات حجم الخط. |
get | Number|null | تسترد حجم الخط عند الإزاحة المحدّدة للحرف. |
get | String|null | تعرض هذه السمة إعداد لون المقدّمة. |
get | String|null | تعرض هذه السمة لون المقدّمة عند موضع الحرف المحدّد. |
get | String|null | تعرض هذه السمة عنوان URL للرابط. |
get | String|null | يستردّ عنوان URL للرابط عند موضع الإزاحة المحدّد للحرف. |
get | Element|null | يستردّ العنصر الشقيق التالي للعنصر. |
get | Container | تعرض هذه السمة العنصر الرئيسي للعنصر الحالي. |
get | Element|null | يتم استرداد العنصر الشقيق السابق للعنصر. |
get | String | تعرض محتوى العنصر كسلسلة نصية. |
get | Text | تعرض هذه السمة محاذاة النص. |
get | Text | تعرض هذه السمة محاذاة النص لحرف واحد. |
get | Integer[] | تعرض هذه السمة مجموعة فهارس النصوص التي تتوافق مع بداية عمليات تنسيق النصوص المميّزة. |
get | Element | يستردّ Element الخاص بالعنصر. |
insert | Text | تُدرج هذه الطريقة النص المحدّد في موضع الإزاحة المحدّد للحرف. |
is | Boolean | تحدّد هذه السمة ما إذا كان العنصر في نهاية Document. |
is | Boolean|null | تعرض هذه السمة إعداد النص الغامق. |
is | Boolean|null | تسترد إعداد النص الغامق عند موضع الحرف المحدّد. |
is | Boolean|null | تعرض هذه السمة إعداد الخط المائل. |
is | Boolean|null | تسترد إعداد الخط المائل عند إزاحة الحرف المحدّدة. |
is | Boolean|null | تسترد إعداد النص المشطوب. |
is | Boolean|null | تسترد إعداد التشطيب عند موضع الحرف المحدّد. |
is | Boolean|null | تعرض هذه السمة إعداد التسطير. |
is | Boolean|null | تعرض هذه الطريقة إعداد التسطير عند موضع الحرف المحدّد. |
merge() | Text|null | يدمج العنصر مع العنصر الشقيق السابق من النوع نفسه. |
remove | Text|null | تزيل هذه الطريقة العنصر من العنصر الأصل. |
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 | يضبط إعداد التسطير لنطاق الأحرف المحدّد. |
مستندات تفصيلية
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 من العنصر الحالي لتعديلها.
استخدِم editAsText لمعالجة محتوى العناصر كنص منسّق. يتجاهل الوضع editAsText العناصر غير النصية (مثل InlineImage وHorizontalRule).
تتم إزالة العناصر الفرعية التي يتم تضمينها بالكامل في نطاق نصي محذوف من العنصر.
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 | النمط المطلوب البحث عنه |
الإرجاع
RangeElement|null — نتيجة بحث تشير إلى موضع نص البحث، أو قيمة فارغة إذا لم تكن هناك أي مطابقة
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
findText(searchPattern, from)
يبحث في محتوى العنصر عن نمط النص المحدّد، بدءًا من نتيجة بحث معيّنة.
لا تتوافق مجموعة فرعية من ميزات التعبير العادي في JavaScript بشكل كامل، مثل مجموعات الالتقاط ومعدّلات الوضع.
تتم مطابقة نمط التعبير العادي المقدَّم بشكل مستقل مع كل كتلة نصية مضمّنة في العنصر الحالي.
المَعلمات
| الاسم | النوع | الوصف |
|---|---|---|
search | String | النمط المطلوب البحث عنه |
from | Range | نتيجة البحث التي تريد البحث منها |
الإرجاع
RangeElement|null: نتيجة بحث تشير إلى الموضع التالي لنص البحث، أو قيمة فارغة إذا لم تكن هناك أي مطابقة
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getAttributes()
يتم استرداد سمات العنصر.
والنتيجة هي عنصر يحتوي على سمة لكل سمة عنصر صالحة، حيث يتطابق اسم كل سمة مع عنصر في التعداد DocumentApp.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
getAttributes(offset)
تعرض هذه الطريقة السمات في موضع الإزاحة المحدّد للحرف.
والنتيجة هي عنصر يحتوي على سمة لكل سمة نصية صالحة، حيث يتطابق اسم كل سمة مع عنصر في التعداد DocumentApp.Attribute.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('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|null: لون الخلفية، منسَّقًا في ترميز 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|null: لون الخلفية، بتنسيق CSS (مثل '#ffffff')
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getFontFamily()
تعرض هذه السمة إعدادات مجموعة الخطوط. يمكن أن يكون الاسم أي خط من قائمة "الخط" في "مستندات Google" أو Google Fonts، وهو حسّاس لحالة الأحرف. تستخدم الطريقتان getFontFamily() وsetFontFamily(fontFamilyName) الآن أسماء السلاسل للخطوط بدلاً من التعداد . على الرغم من أنّ هذا التعداد
قد تم إيقافه نهائيًا، سيظل متاحًا لضمان التوافق مع النصوص البرمجية القديمة.FontFamily
الإرجاع
String|null: عائلة الخط، أو القيمة null إذا كان العنصر يحتوي على قيم متعددة لهذه السمة
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getFontFamily(offset)
تسترد مجموعة الخطوط عند الإزاحة المحدّدة للأحرف. يمكن أن يكون الاسم أي خط من قائمة الخطوط في "مستندات Google" أو Google Fonts، وهو حساس لحالة الأحرف. تستخدم الطريقتان getFontFamily() وsetFontFamily(fontFamilyName)
الآن أسماء السلاسل للخطوط بدلاً من التعداد . على الرغم من أنّ هذا التعداد
قد تم إيقافه نهائيًا، سيظل متاحًا لضمان التوافق مع النصوص البرمجية القديمة.
FontFamily
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/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
getFontSize()
تعرض هذه السمة إعدادات حجم الخط.
الإرجاع
Number|null: حجم الخط، أو قيمة فارغة إذا كان العنصر يحتوي على قيم متعدّدة لهذه السمة
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getFontSize(offset)
تسترد حجم الخط عند الإزاحة المحدّدة للحرف.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('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
getForegroundColor()
تعرض هذه السمة إعداد لون المقدّمة.
الإرجاع
String|null: لون المقدّمة، منسّق في ترميز 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|null: لون المقدّمة، بتنسيق CSS (مثل '#ffffff')
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getLinkUrl()
تعرض هذه السمة عنوان URL للرابط.
الإرجاع
String|null: عنوان URL للرابط، أو null إذا كان العنصر يحتوي على قيم متعددة لهذه السمة
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getLinkUrl(offset)
يستردّ عنوان URL للرابط عند موضع الإزاحة المحدّد للحرف.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('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: عنوان URL للرابط
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getNextSibling()
يستردّ العنصر الشقيق التالي للعنصر.
العنصر الشقيق التالي له العنصر الرئيسي نفسه ويتبع العنصر الحالي.
الإرجاع
Element|null: العنصر الشقيق التالي
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getParent()
تعرض هذه السمة العنصر الرئيسي للعنصر الحالي.
يحتوي العنصر الرئيسي على العنصر الحالي.
الإرجاع
ContainerElement|null: العنصر الرئيسي
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getPreviousSibling()
يتم استرداد العنصر الشقيق السابق للعنصر.
العنصر الشقيق السابق له العنصر الأصلي نفسه ويسبق العنصر الحالي.
الإرجاع
Element|null: العنصر الشقيق السابق
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getText()
تعرض محتوى العنصر كسلسلة نصية.
الإرجاع
String: محتوى العنصر كسلسلة نصية
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getTextAlignment()
تعرض هذه السمة محاذاة النص. تشمل أنواع المحاذاة المتاحة DocumentApp.TextAlignment.NORMAL وDocumentApp.TextAlignment.SUBSCRIPT وDocumentApp.TextAlignment.SUPERSCRIPT.
الإرجاع
TextAlignment|null: نوع محاذاة النص، أو null إذا كان النص يحتوي على أنواع متعدّدة من محاذاة النص أو إذا لم يتم ضبط محاذاة النص مطلقًا
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getTextAlignment(offset)
تعرض هذه السمة محاذاة النص لحرف واحد. تشمل أنواع المحاذاة المتاحة DocumentApp.TextAlignment.NORMAL وDocumentApp.TextAlignment.SUBSCRIPT وDocumentApp.TextAlignment.SUPERSCRIPT.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('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 | إزاحة الحرف |
الإرجاع
TextAlignment|null: نوع محاذاة النص، أو 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()
يستردّ ElementType الخاص بالعنصر.
استخدِم getType() لتحديد النوع الدقيق لعنصر معيّن.
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.'); }
الإرجاع
ElementType: نوع العنصر
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
insertText(offset, text)
تُدرج هذه الطريقة النص المحدّد في موضع الإزاحة المحدّد للحرف.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('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|null: ما إذا كان النص غامقًا، أو قيمة فارغة إذا كان العنصر يحتوي على قيم متعدّدة لهذه السمة
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
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|null: الإعداد الغامق
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
isItalic()
تعرض هذه السمة إعداد الخط المائل.
الإرجاع
Boolean|null: ما إذا كان النص مائلاً، أو قيمة فارغة إذا كان العنصر يحتوي على قيم متعدّدة لهذه السمة
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
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|null: إعداد الخط المائل
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
isStrikethrough()
تسترد إعداد النص المشطوب.
الإرجاع
Boolean|null: ما إذا كان النص مشطوبًا، أو قيمة فارغة إذا كان العنصر يحتوي على قيم متعددة لهذه السمة
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
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|null: إعداد النص المشطوب
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
isUnderline()
تعرض هذه السمة إعداد التسطير.
الإرجاع
Boolean|null: ما إذا كان النص مسطرًا أو قيمة فارغة إذا كان العنصر يحتوي على قيم متعددة لهذه السمة
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
isUnderline(offset)
تعرض هذه الطريقة إعداد التسطير عند موضع الحرف المحدّد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('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()
يدمج العنصر مع العنصر الشقيق السابق من النوع نفسه.
يمكن دمج عناصر من ElementType نفسه فقط. يتم نقل أي عناصر فرعية مضمّنة في العنصر الحالي إلى العنصر الشقيق السابق.
تتم إزالة العنصر الحالي من المستند.
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
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|null: العنصر الذي تمت إزالته
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
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)
تُطبِّق هذه الدالة السمات المحدّدة على نطاق الأحرف المحدّد.
يجب أن تكون مَعلمة السمات المحدّدة عبارة عن عنصر يكون فيه كل اسم خاصية عنصرًا في التعداد DocumentApp.Attribute، وتكون كل قيمة خاصية هي القيمة الجديدة التي سيتم تطبيقها.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/DOCUMENT_ID/edit', ); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('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)
تضبط هذه السمة سمات العنصر.
يجب أن تكون مَعلمة السمات المحدّدة عبارة عن عنصر يكون فيه كل اسم خاصية عنصرًا في التعداد DocumentApp.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
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. تستخدم الطريقتان getFontFamily(offset) وsetFontFamily(fontFamilyName) الآن أسماء السلاسل للخطوط بدلاً من التعداد . على الرغم من أنّ هذا التعداد
قد تم إيقافه نهائيًا، سيظل متاحًا لضمان التوافق مع النصوص البرمجية القديمة.
FontFamily
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/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. تستخدم الطريقتان getFontFamily() وsetFontFamily(fontFamilyName) الآن أسماء السلاسل للخطوط بدلاً من التعداد . على الرغم من أنّ هذا التعداد
قد تم إيقافه نهائيًا، سيظل متاحًا لضمان التوافق مع النصوص البرمجية القديمة.FontFamily
المَعلمات
| الاسم | النوع | الوصف |
|---|---|---|
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)
تضبط هذه السمة حجم الخط.
المَعلمات
| الاسم | النوع | الوصف |
|---|---|---|
size | Number | حجم الخط |
الإرجاع
Text: العنصر الحالي
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
setForegroundColor(startOffset, endOffsetInclusive, color)
تضبط هذه السمة لون المقدّمة لنطاق الأحرف المحدّد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/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)
تضبط هذه السمة إعداد الخط المائل.
المَعلمات
| الاسم | النوع | الوصف |
|---|---|---|
italic | Boolean | إعداد الخط المائل |
الإرجاع
Text: العنصر الحالي
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
setItalic(startOffset, endOffsetInclusive, italic)
يضبط هذا الإجراء إعداد الخط المائل لنطاق الأحرف المحدّد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/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)
تضبط هذه السمة محاذاة النص لنطاق أحرف معيّن. تشمل أنواع المحاذاة المتاحة DocumentApp.TextAlignment.NORMAL وDocumentApp.TextAlignment.SUBSCRIPT وDocumentApp.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 | Integer | تمثّل هذه السمة إزاحة بداية نطاق الأحرف. |
end | Integer | الإزاحة النهائية لنطاق الأحرف (شاملة). |
text | Text | نوع محاذاة النص المطلوب تطبيقه. |
الإرجاع
Text: العنصر الحالي
التفويض
تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
setTextAlignment(textAlignment)
تضبط هذه السمة محاذاة النص. تشمل أنواع المحاذاة المتاحة DocumentApp.TextAlignment.NORMAL وDocumentApp.TextAlignment.SUBSCRIPT وDocumentApp.TextAlignment.SUPERSCRIPT.
// Make the entire first paragraph in the active tab be superscript. 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)
يضبط إعداد التسطير لنطاق الأحرف المحدّد.
// 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