عنصر يمثل منطقة نص منسق. النص الموجود في Document
مضمّن في Text
عنصر.
يمكن تضمين عنصر Text
داخل Equation
أو EquationFunction
أو
ListItem
أو Paragraph
، ولكن لا يمكن أن يحتوي على أي عنصر آخر. لمزيد من المعلومات حول بنية المستند، راجع دليل توسيع نطاق مستندات Google.
var body = DocumentApp.getActiveDocument().getBody(); // Use editAsText to obtain a single text element containing // all the characters in the document. var text = body.editAsText(); // Insert text at the beginning of the document. text.insertText(0, 'Inserted text.\n'); // Insert text at the end of the document. text.appendText('\nAppended text.'); // Make the first half of the document blue. text.setForegroundColor(0, text.getText().length / 2, '#00FFFF');
الطُرق
الطريقة | نوع الإرجاع | وصف قصير |
---|---|---|
appendText(text) | Text | لإضافة النص المحدد إلى نهاية منطقة النص هذه. |
copy() | Text | لعرض نسخة تفصيلية ومفصلة للعنصر الحالي. |
deleteText(startOffset, endOffsetInclusive) | Text | لحذف نطاق من النصوص. |
editAsText() | Text | يمكن الحصول على إصدار Text للعنصر الحالي للتعديل. |
findText(searchPattern) | RangeElement | للبحث في محتويات العنصر عن نمط النص المحدد باستخدام التعبيرات العادية. |
findText(searchPattern, from) | RangeElement | للبحث في محتويات العنصر عن نمط النص المحدد، بدءًا من نتيجة بحث معينة. |
getAttributes() | Object | لاسترداد سمات العنصر. |
getAttributes(offset) | Object | لاسترداد السمات عند إزاحة الحرف المحدد. |
getBackgroundColor() | String | لاسترداد إعداد لون الخلفية. |
getBackgroundColor(offset) | String | لاسترداد لون الخلفية عند إزاحة الحرف المحدد. |
getFontFamily() | String | لاسترداد إعداد مجموعة الخطوط. |
getFontFamily(offset) | String | لاسترداد مجموعة الخطوط عند إزاحة الحرف المحدد. |
getFontSize() | Number | لاسترداد إعداد حجم الخط. |
getFontSize(offset) | Number | لاسترداد حجم الخط عند إزاحة الحرف المحدد. |
getForegroundColor() | String | لاسترداد إعداد لون المقدمة. |
getForegroundColor(offset) | String | لاسترداد لون المقدمة عند إزاحة الحرف المحدد. |
getLinkUrl() | String | لاسترداد عنوان URL للرابط. |
getLinkUrl(offset) | String | لاسترداد عنوان URL للرابط عند إزاحة الحرف المحدد. |
getNextSibling() | Element | لاسترداد عنصر شقيق العنصر التالي. |
getParent() | ContainerElement | لاسترداد العنصر الرئيسي للعنصر. |
getPreviousSibling() | Element | لاسترداد العنصر الشقيق السابق للعنصر. |
getText() | String | لاسترداد محتويات العنصر كسلسلة نصية. |
getTextAlignment() | TextAlignment | للحصول على محاذاة النص. |
getTextAlignment(offset) | TextAlignment | للحصول على محاذاة النص لحرف واحد. |
getTextAttributeIndices() | Integer[] | لاسترداد مجموعة فهارس نصية تتوافق مع بداية تشغيل أشكال مختلفة من النص. |
getType() | ElementType | لاسترداد ElementType للعنصر. |
insertText(offset, text) | Text | إدراج النص المحدد عند إزاحة الحرف المحدد. |
isAtDocumentEnd() | Boolean | لتحديد ما إذا كان العنصر في نهاية Document . |
isBold() | Boolean | لاسترداد الإعداد بالخط الغامق. |
isBold(offset) | Boolean | لاسترداد الإعداد بالخط العريض عند إزاحة الحرف المحدد. |
isItalic() | Boolean | لاسترداد الإعداد المائل. |
isItalic(offset) | Boolean | لاسترداد الإعداد المائل بإزاحة الحرف المحدد. |
isStrikethrough() | Boolean | لاسترداد الإعداد يتوسطه خط. |
isStrikethrough(offset) | Boolean | لاسترداد الإعداد يتوسطه خط عند إزاحة الحرف المحدد. |
isUnderline() | Boolean | لاسترداد إعداد التسطير. |
isUnderline(offset) | Boolean | لاسترداد إعداد التسطير عند إزاحة الحرف المحدد. |
merge() | Text | لدمج العنصر مع العنصر المماثل السابق من نفس النوع. |
removeFromParent() | Text | لإزالة العنصر من العنصر الرئيسي. |
replaceText(searchPattern, replacement) | Element | لاستبدال جميع مواضع ورود نمط نص معين بسلسلة بديلة معينة، باستخدام التعبيرات العادية. |
setAttributes(startOffset, endOffsetInclusive, attributes) | Text | لتطبيق السمات المحددة على نطاق الأحرف المحدد. |
setAttributes(attributes) | Text | لتعيين سمات العنصر. |
setBackgroundColor(startOffset, endOffsetInclusive, color) | Text | لتعيين لون الخلفية لنطاق الأحرف المحدد. |
setBackgroundColor(color) | Text | لتعيين لون الخلفية. |
setBold(bold) | Text | لضبط الإعداد الغامق. |
setBold(startOffset, endOffsetInclusive, bold) | Text | لضبط الإعداد الغامق لنطاق الأحرف المحدد. |
setFontFamily(startOffset, endOffsetInclusive, fontFamilyName) | Text | لتعيين مجموعة الخطوط لنطاق الأحرف المحدد. |
setFontFamily(fontFamilyName) | Text | لتعيين مجموعة الخطوط. |
setFontSize(startOffset, endOffsetInclusive, size) | Text | لتعيين حجم الخط لنطاق الأحرف المحدد. |
setFontSize(size) | Text | لتعيين حجم الخط. |
setForegroundColor(startOffset, endOffsetInclusive, color) | Text | لتعيين لون المقدمة لنطاق الأحرف المحدد. |
setForegroundColor(color) | Text | لضبط لون المقدمة. |
setItalic(italic) | Text | لضبط الإعداد المائل. |
setItalic(startOffset, endOffsetInclusive, italic) | Text | لضبط الإعداد المائل لنطاق الأحرف المحدد. |
setLinkUrl(startOffset, endOffsetInclusive, url) | Text | لتعيين عنوان URL للرابط لعدد الأحرف المحدد. |
setLinkUrl(url) | Text | لتعيين عنوان URL للرابط. |
setStrikethrough(strikethrough) | Text | لضبط الإعداد الذي يتوسطه خط. |
setStrikethrough(startOffset, endOffsetInclusive, strikethrough) | Text | لضبط الإعداد الذي يتوسطه خط لنطاق الأحرف المحدد. |
setText(text) | Text | لتعيين محتويات النص. |
setTextAlignment(startOffset, endOffsetInclusive, textAlignment) | Text | لتعيين محاذاة النص لنطاق أحرف معين. |
setTextAlignment(textAlignment) | Text | لضبط محاذاة النص. |
setUnderline(underline) | Text | لتعيين إعداد التسطير. |
setUnderline(startOffset, endOffsetInclusive, underline) | Text | لتعيين إعداد التسطير لنطاق الأحرف المحدد. |
الوثائق التفصيلية
appendText(text)
لإضافة النص المحدد إلى نهاية منطقة النص هذه.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Adds the text, 'Sample body text,' to the end of the document body. const text = body.editAsText().appendText('Sample body text');
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
text | String | النص المطلوب إلحاقه. |
تذكرة ذهاب وعودة
Text
— العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
copy()
لعرض نسخة تفصيلية ومفصلة للعنصر الحالي.
يتم أيضًا نسخ أي عناصر فرعية موجودة في العنصر. العنصر الجديد ليس له أصل.
تذكرة ذهاب وعودة
Text
— النسخة الجديدة.
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
deleteText(startOffset, endOffsetInclusive)
لحذف نطاق من النصوص.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Deletes the first 10 characters in the body. const text = body.editAsText().deleteText(0, 9);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
startOffset | Integer | إزاحة الحرف من الحرف الأول المراد حذفه. |
endOffsetInclusive | Integer | إزاحة الحرف الأخير من الحرف المراد حذفه. |
تذكرة ذهاب وعودة
Text
— العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
editAsText()
يمكن الحصول على إصدار Text
للعنصر الحالي للتعديل.
يمكنك استخدام editAsText
لمعالجة محتوى العناصر كنص منسق. يتجاهل وضع editAsText
العناصر غير النصية (مثل InlineImage
وHorizontalRule
).
تتم إزالة العناصر الفرعية المضمنة بالكامل في نطاق نصي محذوف من العنصر.
var body = DocumentApp.getActiveDocument().getBody(); // Insert two paragraphs separated by a paragraph containing an // horizontal rule. body.insertParagraph(0, "An editAsText sample."); body.insertHorizontalRule(0); body.insertParagraph(0, "An example."); // Delete " sample.\n\n An" removing the horizontal rule in the process. body.editAsText().deleteText(14, 25);
تذكرة ذهاب وعودة
Text
— إصدار نصي من العنصر الحالي
findText(searchPattern)
للبحث في محتويات العنصر عن نمط النص المحدد باستخدام التعبيرات العادية.
هناك مجموعة فرعية من ميزات التعبير العادي في جافا سكريبت غير متوافقة بالكامل، مثل التقاط المجموعات ومُعدِّلات الوضع.
تتم مطابقة نمط التعبير العادي المقدَّم بشكل مستقل مع كل جزء نص يتضمنه العنصر الحالي.
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
searchPattern | String | النمط المراد البحث عنه |
تذكرة ذهاب وعودة
RangeElement
— نتيجة بحث تشير إلى موضع نص البحث، أو تكون فارغة في حال عدم وجود تطابق
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
findText(searchPattern, from)
للبحث في محتويات العنصر عن نمط النص المحدد، بدءًا من نتيجة بحث معينة.
هناك مجموعة فرعية من ميزات التعبير العادي في جافا سكريبت غير متوافقة بالكامل، مثل التقاط المجموعات ومُعدِّلات الوضع.
تتم مطابقة نمط التعبير العادي المقدَّم بشكل مستقل مع كل جزء نص يتضمنه العنصر الحالي.
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
searchPattern | String | النمط المراد البحث عنه |
from | RangeElement | نتيجة البحث للبحث من |
تذكرة ذهاب وعودة
RangeElement
— نتيجة بحث تشير إلى الموضع التالي لنص البحث، أو تكون فارغة إذا لم يكن هناك
تطابق
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getAttributes()
لاسترداد سمات العنصر.
والنتيجة هي كائن يحتوي على خاصية لكل سمة عنصر صالحة حيث يتطابق كل اسم خاصية مع عنصر في قائمة تعداد DocumentApp.Attribute
.
var body = DocumentApp.getActiveDocument().getBody(); // Append a styled paragraph. var par = body.appendParagraph('A bold, italicized paragraph.'); par.setBold(true); par.setItalic(true); // Retrieve the paragraph's attributes. var atts = par.getAttributes(); // Log the paragraph attributes. for (var att in atts) { Logger.log(att + ":" + atts[att]); }
تذكرة ذهاب وعودة
Object
— سمات العنصر.
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getAttributes(offset)
لاسترداد السمات عند إزاحة الحرف المحدد.
والنتيجة هي كائن يحتوي على خاصية لكل سمة نصية صالحة حيث يتوافق كل اسم خاصية مع عنصر في تعداد DocumentApp.Attribute
.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Declares style attributes. const style = {} style[DocumentApp.Attribute.BOLD] = true; style[DocumentApp.Attribute.ITALIC] = true; style[DocumentApp.Attribute.FONT_SIZE] = 29; // Sets the style attributes to the document body. const text = body.editAsText(); text.setAttributes(style); // Gets the style attributes applied to the eleventh character in the // body and logs them to the console. const attributes = text.getAttributes(10); console.log(attributes);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
offset | Integer | إزاحة الحرف. |
تذكرة ذهاب وعودة
Object
— سمات العنصر.
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getBackgroundColor()
لاسترداد إعداد لون الخلفية.
تذكرة ذهاب وعودة
String
- لون الخلفية، ويكون منسقًا في صيغة CSS (مثل '#ffffff'
)، أو يكون فارغًا إذا كان العنصر يحتوي على قيم متعددة لهذه السمة
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getBackgroundColor(offset)
لاسترداد لون الخلفية عند إزاحة الحرف المحدد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456'); // Gets the document body. const body = doc.getBody(); // Sets the background color of the first 3 characters in the body. const text = body.editAsText().setBackgroundColor(0, 2, '#FFC0CB'); // Gets the background color of the first character in the body. const backgroundColor = text.getBackgroundColor(0); // Logs the background color to the console. console.log(backgroundColor);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
offset | Integer | إزاحة الحرف. |
تذكرة ذهاب وعودة
String
— لون الخلفية، بتنسيق في صيغة CSS (مثل '#ffffff'
).
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getFontFamily()
لاسترداد إعداد مجموعة الخطوط. يمكن أن يكون الاسم بأي خط من قائمة الخطوط في المستندات أو خطوط Google، ويكون حساسًا لحالة الأحرف. تستخدم طريقتا getFontFamily()
وsetFontFamily(fontFamilyName)
الآن أسماء السلاسل للخطوط بدلاً من التعداد
. على الرغم من أنه تم إيقاف هذا التعداد،
فسيتم الإبقاء عليه متوافقًا مع النصوص البرمجية القديمة.FontFamily
تذكرة ذهاب وعودة
String
— عائلة الخطوط، أو قيمة فارغة إذا كان العنصر يحتوي على قيم متعددة لهذه السمة
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getFontFamily(offset)
لاسترداد مجموعة الخطوط عند إزاحة الحرف المحدد. يمكن أن يكون الاسم بأي خط من قائمة الخطوط في المستندات أو خطوط Google، ويكون حساسًا لحالة الأحرف. تستخدم طريقتا 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/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the font of the first 16 characters to Impact. const text = body.editAsText().setFontFamily(0, 15, 'Impact'); // Gets the font family of the 16th character in the document body. const fontFamily = text.getFontFamily(15); // Logs the font family to the console. console.log(fontFamily);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
offset | Integer | إزاحة الحرف. |
تذكرة ذهاب وعودة
String
— مجموعة الخطوط.
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getFontSize()
لاسترداد إعداد حجم الخط.
تذكرة ذهاب وعودة
Number
— حجم الخط أو قيمة فارغة إذا كان العنصر يحتوي على قيم متعددة لهذه السمة
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getFontSize(offset)
لاسترداد حجم الخط عند إزاحة الحرف المحدد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the font size of the first 13 characters to 15. const text = body.editAsText().setFontSize(0, 12, 15); // Gets the font size of the first character. const fontSize = text.getFontSize(0); // Logs the font size to the console. console.log(fontSize);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
offset | Integer | إزاحة الحرف. |
تذكرة ذهاب وعودة
Number
— حجم الخط.
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getForegroundColor()
لاسترداد إعداد لون المقدمة.
تذكرة ذهاب وعودة
String
— لون المقدمة، يكون منسقًا في صيغة CSS (مثل '#ffffff'
)، أو يكون فارغًا إذا كان العنصر يحتوي على قيم متعددة لهذه السمة
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getForegroundColor(offset)
لاسترداد لون المقدمة عند إزاحة الحرف المحدد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the foreground color of the first 3 characters in the document body. const text = body.editAsText().setForegroundColor(0, 2, '#0000FF'); // Gets the foreground color of the first character in the document body. const foregroundColor = text.getForegroundColor(0); // Logs the foreground color to the console. console.log(foregroundcolor);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
offset | Integer | إزاحة الحرف. |
تذكرة ذهاب وعودة
String
— لون المقدمة بتنسيق بتنسيق CSS (مثل '#ffffff'
).
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getLinkUrl()
لاسترداد عنوان 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/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Applies a link to the first 10 characters in the body. const text = body.editAsText().setLinkUrl(0, 9, 'https://www.example.com/'); // Gets the URL of the link from the first character. const link = text.getLinkUrl(0); // Logs the link URL to the console. console.log(link);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
offset | Integer | إزاحة الحرف. |
تذكرة ذهاب وعودة
String
— عنوان URL للرابط.
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getNextSibling()
لاسترداد عنصر شقيق العنصر التالي.
العنصر التابع التالي له العنصر الرئيسي نفسه ويتبع العنصر الحالي.
تذكرة ذهاب وعودة
Element
: العنصر التابع التالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getParent()
لاسترداد العنصر الرئيسي للعنصر.
يحتوي العنصر الرئيسي على العنصر الحالي.
تذكرة ذهاب وعودة
ContainerElement
— العنصر الرئيسي.
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPreviousSibling()
لاسترداد العنصر الشقيق السابق للعنصر.
ويكون للعنصر الرئيسي السابق العنصر الرئيسي نفسه ويسبق العنصر الحالي.
تذكرة ذهاب وعودة
Element
— العنصر السابق التابع.
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getText()
لاسترداد محتويات العنصر كسلسلة نصية.
تذكرة ذهاب وعودة
String
— محتويات العنصر كسلسلة نصية
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getTextAlignment()
للحصول على محاذاة النص. أنواع المحاذاة المتاحة هي DocumentApp.TextAlignment.NORMAL
وDocumentApp.TextAlignment.SUBSCRIPT
وDocumentApp.TextAlignment.SUPERSCRIPT
.
تذكرة ذهاب وعودة
TextAlignment
: نوع محاذاة النص، أو null
إذا كان النص يحتوي على أنواع متعددة من محاذاة النص
أو إذا لم يتم ضبط محاذاة النص مطلقًا
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getTextAlignment(offset)
للحصول على محاذاة النص لحرف واحد. أنواع المحاذاة المتاحة هي DocumentApp.TextAlignment.NORMAL
وDocumentApp.TextAlignment.SUBSCRIPT
وDocumentApp.TextAlignment.SUPERSCRIPT
.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the text alignment of the document body to NORMAL. const text = body.editAsText().setTextAlignment(DocumentApp.TextAlignment.NORMAL); // Gets the text alignment of the ninth character. const alignment = text.getTextAlignment(8); // Logs the text alignment to the console. console.log(alignment.toString());
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
offset | Integer | إزاحة الحرف. |
تذكرة ذهاب وعودة
TextAlignment
— نوع محاذاة النص، أو null
إذا لم يتم ضبط محاذاة النص مطلقًا.
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getTextAttributeIndices()
لاسترداد مجموعة فهارس نصية تتوافق مع بداية تشغيل أشكال مختلفة من النص.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Gets the text indices at which text formatting changes. const indices = body.editAsText().getTextAttributeIndices(); // Logs the indices to the console. console.log(indices.toString());
تذكرة ذهاب وعودة
Integer[]
— مجموعة فهارس النص التي يتغير فيها تنسيق النص.
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getType()
لاسترداد ElementType
للعنصر.
استخدم getType()
لتحديد النوع الدقيق لعنصر معيّن.
var body = DocumentApp.getActiveDocument().getBody(); // Obtain the first element in the document body. var firstChild = body.getChild(0); // Use getType() to determine the element's type. if (firstChild.getType() == DocumentApp.ElementType.PARAGRAPH) { Logger.log('The first element is a paragraph.'); } else { Logger.log('The first element is not a paragraph.'); }
تذكرة ذهاب وعودة
ElementType
— نوع العنصر.
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertText(offset, text)
إدراج النص المحدد عند إزاحة الحرف المحدد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Inserts the text, 'Sample inserted text', at the start of the body content. const text = body.editAsText().insertText(0, 'Sample inserted text');
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
offset | Integer | إزاحة الحرف التي سيتم إدراج النص بها. |
text | String | النص المطلوب إدراجه. |
تذكرة ذهاب وعودة
Text
— العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isAtDocumentEnd()
لتحديد ما إذا كان العنصر في نهاية Document
.
تذكرة ذهاب وعودة
Boolean
— ما إذا كان العنصر في نهاية المستند أم لا.
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isBold()
لاسترداد الإعداد بالخط الغامق.
تذكرة ذهاب وعودة
Boolean
— سواء كان النص غامقًا أو خالٍ إذا كان العنصر يحتوي على قيم متعددة
لهذه السمة
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isBold(offset)
لاسترداد الإعداد بالخط العريض عند إزاحة الحرف المحدد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Bolds the first 4 characters in the document body. const text = body.editAsText().setBold(0, 3, true); // Gets whether or not the text is bold. const bold = text.editAsText().isBold(0); // Logs the text's bold setting to the console console.log(bold);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
offset | Integer | إزاحة الحرف. |
تذكرة ذهاب وعودة
Boolean
— الإعداد الغامق.
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isItalic()
لاسترداد الإعداد المائل.
تذكرة ذهاب وعودة
Boolean
— سواء كان النص مائلاً أو فارغًا إذا كان العنصر يحتوي على قيم متعددة لهذه السمة
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isItalic(offset)
لاسترداد الإعداد المائل بإزاحة الحرف المحدد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the first 13 characters of the document body to italic. const text = body.editAsText().setItalic(0, 12, true); // Gets whether the fifth character in the document body is set to // italic and logs it to the console. const italic = text.isItalic(4); console.log(italic);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
offset | Integer | إزاحة الحرف. |
تذكرة ذهاب وعودة
Boolean
— الإعداد المائل.
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isStrikethrough()
لاسترداد الإعداد يتوسطه خط.
تذكرة ذهاب وعودة
Boolean
— سواء كان النص يتوسطه خط أو يكون فارغًا إذا كان العنصر يحتوي على قيم متعددة
لهذه السمة
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isStrikethrough(offset)
لاسترداد الإعداد يتوسطه خط عند إزاحة الحرف المحدد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the first 17 characters of the document body to strikethrough. const text = body.editAsText().setStrikethrough(0, 16, true); // Gets whether the first character in the document body is set to // strikethrough and logs it to the console. const strikethrough = text.isStrikethrough(0); console.log(strikethrough);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
offset | Integer | إزاحة الحرف. |
تذكرة ذهاب وعودة
Boolean
— إعداد يتوسطه خط.
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isUnderline()
لاسترداد إعداد التسطير.
تذكرة ذهاب وعودة
Boolean
: تحدّد هذه السمة ما إذا كان النص تحته خط أم لا إذا كان يحتوي على قيم متعدّدة لهذه السمة.
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isUnderline(offset)
لاسترداد إعداد التسطير عند إزاحة الحرف المحدد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the first 13 characters of the document body to underline. const text = body.editAsText().setUnderline(0, 12, false); // Gets whether the first character in the document body is set to // underline and logs it to the console const underline = text.editAsText().isUnderline(0); console.log(underline);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
offset | Integer | إزاحة الحرف. |
تذكرة ذهاب وعودة
Boolean
— إعداد التسطير
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
merge()
لدمج العنصر مع العنصر المماثل السابق من نفس النوع.
لا يمكن دمج سوى العناصر من ElementType
نفسها. يتم نقل أي عناصر فرعية مضمَّنة في العنصر الحالي إلى العنصر التابع السابق.
تتم إزالة العنصر الحالي من المستند.
var body = DocumentApp.getActiveDocument().getBody(); // Example 1: Merge paragraphs // Append two paragraphs to the document. var par1 = body.appendParagraph('Paragraph 1.'); var par2 = body.appendParagraph('Paragraph 2.'); // Merge the newly added paragraphs into a single paragraph. par2.merge(); // Example 2: Merge table cells // Create a two-dimensional array containing the table's cell contents. var cells = [ ['Row 1, Cell 1', 'Row 1, Cell 2'], ['Row 2, Cell 1', 'Row 2, Cell 2'] ]; // Build a table from the array. var table = body.appendTable(cells); // Get the first row in the table. var row = table.getRow(0); // Get the two cells in this row. var cell1 = row.getCell(0); var cell2 = row.getCell(1); // Merge the current cell into its preceding sibling element. var merged = cell2.merge();
تذكرة ذهاب وعودة
Text
— العنصر الذي تم دمجه.
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removeFromParent()
لإزالة العنصر من العنصر الرئيسي.
var body = DocumentApp.getActiveDocument().getBody(); // Remove all images in the document body. var imgs = body.getImages(); for (var i = 0; i < imgs.length; i++) { imgs[i].removeFromParent(); }
تذكرة ذهاب وعودة
Text
— العنصر الذي تمت إزالته.
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
replaceText(searchPattern, replacement)
لاستبدال جميع مواضع ورود نمط نص معين بسلسلة بديلة معينة، باستخدام التعبيرات العادية.
يتم تمرير نمط البحث في صورة سلسلة، وليس كائن تعبير عادي في JavaScript. لهذا السبب، ستحتاج إلى إزالة أي شرطة مائلة للخلف في النمط.
تستخدم هذه الطرق مكتبة التعبير العادي RE2 من Google، ما يحد من البنية المتوافقة.
تتم مطابقة نمط التعبير العادي المقدَّم بشكل مستقل مع كل جزء نص يتضمنه العنصر الحالي.
var body = DocumentApp.getActiveDocument().getBody(); // Clear the text surrounding "Apps Script", with or without text. body.replaceText("^.*Apps ?Script.*$", "Apps Script");
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
searchPattern | String | نمط regex للبحث عنه |
replacement | String | النص المراد استخدامه كبديل |
تذكرة ذهاب وعودة
Element
- العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setAttributes(startOffset, endOffsetInclusive, attributes)
لتطبيق السمات المحددة على نطاق الأحرف المحدد.
يجب أن تكون معلمة السمات المحددة كائنًا يكون فيه كل اسم خاصية عنصرًا في تعداد DocumentApp.Attribute
وتكون كل قيمة خاصية هي القيمة الجديدة التي سيتم تطبيقها.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body and edits as text. const body = doc.getBody().editAsText(); // Declares style attributes for font size and font family. const style = {} style[DocumentApp.Attribute.FONT_SIZE] = 20 ; style[DocumentApp.Attribute.FONT_FAMILY] = 'Impact'; // Sets the style attributes to the first 9 characters in the document body. const text = body.setAttributes(0, 8, style);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
startOffset | Integer | إزاحة بداية نطاق النص. |
endOffsetInclusive | Integer | إزاحة نهاية نطاق النص. |
attributes | Object | سمات العنصر. |
تذكرة ذهاب وعودة
Text
— العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setAttributes(attributes)
لتعيين سمات العنصر.
يجب أن تكون معلمة السمات المحددة كائنًا يكون فيه كل اسم خاصية عنصرًا في تعداد DocumentApp.Attribute
وتكون كل قيمة خاصية هي القيمة الجديدة التي سيتم تطبيقها.
var body = DocumentApp.getActiveDocument().getBody(); // Define a custom paragraph style. var style = {}; style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.RIGHT; style[DocumentApp.Attribute.FONT_FAMILY] = 'Calibri'; style[DocumentApp.Attribute.FONT_SIZE] = 18; style[DocumentApp.Attribute.BOLD] = true; // Append a plain paragraph. var par = body.appendParagraph('A paragraph with custom style.'); // Apply the custom style. par.setAttributes(style);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
attributes | Object | سمات العنصر. |
تذكرة ذهاب وعودة
Text
— العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setBackgroundColor(startOffset, endOffsetInclusive, color)
لتعيين لون الخلفية لنطاق الأحرف المحدد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the background color of the first 3 characters in the // document body to hex color #0000FF. const text = body.editAsText().setBackgroundColor(0, 2, '#0000FF');
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
startOffset | Integer | إزاحة بداية نطاق النص. |
endOffsetInclusive | Integer | إزاحة نهاية نطاق النص. |
color | String | لون الخلفية، يتم تنسيقه بتنسيق CSS (مثل '#ffffff' ) |
تذكرة ذهاب وعودة
Text
— العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setBackgroundColor(color)
لتعيين لون الخلفية.
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
color | String | لون الخلفية، بتنسيق في صيغة CSS (مثل '#ffffff' ) |
تذكرة ذهاب وعودة
Text
- العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setBold(bold)
لضبط الإعداد الغامق.
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
bold | Boolean | الإعداد الغامق |
تذكرة ذهاب وعودة
Text
- العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setBold(startOffset, endOffsetInclusive, bold)
لضبط الإعداد الغامق لنطاق الأحرف المحدد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the first 11 characters in the document body to bold. const text = body.editAsText().setBold(0, 10, true);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
startOffset | Integer | إزاحة بداية نطاق النص. |
endOffsetInclusive | Integer | إزاحة نهاية نطاق النص. |
bold | Boolean | الإعداد الغامق. |
تذكرة ذهاب وعودة
Text
— العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setFontFamily(startOffset, endOffsetInclusive, fontFamilyName)
لتعيين مجموعة الخطوط لنطاق الأحرف المحدد. يمكن أن يكون الاسم بأي خط من قائمة
الخطوط في المستندات أو خطوط Google، ويكون حساسًا لحالة الأحرف.
سيتم عرض أسماء الخطوط غير المعروفة كـ 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/abc123456/edit'); // Gets body of the document. const body = doc.getBody(); // Sets the font of the first 4 characters in the document body to Roboto. const text = body.editAsText().setFontFamily(0, 3, 'Roboto');
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
startOffset | Integer | إزاحة بداية نطاق النص. |
endOffsetInclusive | Integer | إزاحة نهاية نطاق النص. |
fontFamilyName | String | اسم مجموعة الخطوط، من قائمة الخطوط في "مستندات Google" أو "خطوط Google". |
تذكرة ذهاب وعودة
Text
— العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setFontFamily(fontFamilyName)
لتعيين مجموعة الخطوط. يمكن أن يكون الاسم بأي خط من قائمة الخطوط في المستندات أو خطوط Google، ويكون حساسًا لحالة الأحرف. سيتم عرض أسماء
الخطوط غير المعروفة كـ Arial. تستخدم طريقتا getFontFamily()
وsetFontFamily(fontFamilyName)
الآن أسماء السلاسل للخطوط بدلاً من التعداد
. على الرغم من أنه تم إيقاف هذا التعداد،
فسيتم الإبقاء عليه متوافقًا مع النصوص البرمجية القديمة.FontFamily
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
fontFamilyName | String | اسم مجموعة الخطوط، من قائمة الخطوط في "مستندات Google" أو "خطوط Google" |
تذكرة ذهاب وعودة
Text
- العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setFontSize(startOffset, endOffsetInclusive, size)
لتعيين حجم الخط لنطاق الأحرف المحدد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the size of the first 11 characters in the document body to 12. const text = body.editAsText().setFontSize(0, 10, 12);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
startOffset | Integer | إزاحة بداية نطاق النص. |
endOffsetInclusive | Integer | إزاحة نهاية نطاق النص. |
size | Number | حجم الخط. |
تذكرة ذهاب وعودة
Text
— العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setFontSize(size)
لتعيين حجم الخط.
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
size | Number | حجم الخط |
تذكرة ذهاب وعودة
Text
- العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setForegroundColor(startOffset, endOffsetInclusive, color)
لتعيين لون المقدمة لنطاق الأحرف المحدد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the foreground color of the first 2 characters in the // document body to hex color #FF0000. const text = body.editAsText().setForegroundColor(0, 1, '#FF0000'); // Gets the foreground color for the second character in the document body. const foregroundColor = text.getForegroundColor(1); // Logs the foreground color to the console. console.log(foregroundColor);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
startOffset | Integer | إزاحة بداية نطاق النص. |
endOffsetInclusive | Integer | إزاحة نهاية نطاق النص. |
color | String | لون المقدمة بتنسيق منسق في CSS (مثل '#ffffff' ). |
تذكرة ذهاب وعودة
Text
— العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setForegroundColor(color)
لضبط لون المقدمة.
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
color | String | لون المقدمة، وتنسيقها في صيغة CSS (مثل '#ffffff' ) |
تذكرة ذهاب وعودة
Text
- العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setItalic(italic)
لضبط الإعداد المائل.
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
italic | Boolean | الإعداد المائل |
تذكرة ذهاب وعودة
Text
- العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setItalic(startOffset, endOffsetInclusive, italic)
لضبط الإعداد المائل لنطاق الأحرف المحدد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the first 11 characters in the document body to italic. const text = body.editAsText().setItalic(0, 10, true);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
startOffset | Integer | إزاحة بداية نطاق النص. |
endOffsetInclusive | Integer | إزاحة نهاية نطاق النص. |
italic | Boolean | الإعداد المائل. |
تذكرة ذهاب وعودة
Text
— العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setLinkUrl(startOffset, endOffsetInclusive, url)
لتعيين عنوان URL للرابط لعدد الأحرف المحدد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Applies a link to the first 11 characters in the body. const text = body.editAsText().setLinkUrl(0, 10, 'https://example.com');
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
startOffset | Integer | إزاحة بداية نطاق النص. |
endOffsetInclusive | Integer | إزاحة نهاية نطاق النص. |
url | String | عنوان 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/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the first 11 characters in the document body to strikethrough. const text = body.editAsText().setStrikethrough(0, 10, true);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
startOffset | Integer | إزاحة بداية نطاق النص. |
endOffsetInclusive | Integer | إزاحة نهاية نطاق النص. |
strikethrough | Boolean | الإعداد يتوسطه خط. |
تذكرة ذهاب وعودة
Text
— العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setText(text)
لتعيين محتويات النص.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Replaces the contents of the body with the text, 'New body text.' const text = body.editAsText().setText('New body text.');
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
text | String | محتويات النص الجديد. |
تذكرة ذهاب وعودة
Text
— العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setTextAlignment(startOffset, endOffsetInclusive, textAlignment)
لتعيين محاذاة النص لنطاق أحرف معين. أنواع التوافق المتاحة هي DocumentApp.TextAlignment.NORMAL
وDocumentApp.TextAlignment.SUBSCRIPT
وDocumentApp.TextAlignment.SUPERSCRIPT
.
// Make the first character in the first paragraph be superscript. var text = DocumentApp.getActiveDocument().getBody().getParagraphs()[0].editAsText(); text.setTextAlignment(0, 0, DocumentApp.TextAlignment.SUPERSCRIPT);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
startOffset | Integer | إزاحة البداية لنطاق الأحرف. |
endOffsetInclusive | Integer | الإزاحة النهائية لنطاق الأحرف (شامل). |
textAlignment | TextAlignment | نوع محاذاة النص المطلوب تطبيقه. |
تذكرة ذهاب وعودة
Text
— العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setTextAlignment(textAlignment)
لضبط محاذاة النص. أنواع المحاذاة المتاحة هي DocumentApp.TextAlignment.NORMAL
وDocumentApp.TextAlignment.SUBSCRIPT
وDocumentApp.TextAlignment.SUPERSCRIPT
.
// Make the entire first paragraph be superscript. var text = DocumentApp.getActiveDocument().getBody().getParagraphs()[0].editAsText(); text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
textAlignment | TextAlignment | نوع المحاذاة النصية المراد تطبيقها |
تذكرة ذهاب وعودة
Text
- العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setUnderline(underline)
لتعيين إعداد التسطير.
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
underline | Boolean | إعداد التسطير |
تذكرة ذهاب وعودة
Text
- العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setUnderline(startOffset, endOffsetInclusive, underline)
لتعيين إعداد التسطير لنطاق الأحرف المحدد.
// Opens the Docs file by its URL. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the URL with your own. const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit'); // Gets the document body. const body = doc.getBody(); // Sets the first 11 characters in the document body to underline. const text = body.editAsText().setUnderline(0, 10, true);
المعلَمات
الاسم | النوع | الوصف |
---|---|---|
startOffset | Integer | إزاحة بداية نطاق النص. |
endOffsetInclusive | Integer | إزاحة نهاية نطاق النص. |
underline | Boolean | إعداد التسطير. |
تذكرة ذهاب وعودة
Text
— العنصر الحالي
التفويض
تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents