Class Text

Text

عنصر يمثّل منطقة نص منسّق يجب أن يكون كل النص في 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');

الطُرق

الطريقةنوع القيمة التي تم إرجاعهاوصف قصير
appendText(text)Textتضيف هذه الطريقة النص المحدّد إلى نهاية منطقة النص هذه.
copy()Textتعرض نسخة منفصلة وعميقة من العنصر الحالي.
deleteText(startOffset, endOffsetInclusive)Textلحذف نطاق من النص
editAsText()Textيحصل على نسخة Text من العنصر الحالي لتعديلها.
findText(searchPattern)RangeElement|nullيبحث في محتوى العنصر عن نمط النص المحدّد باستخدام التعبيرات العادية.
findText(searchPattern, from)RangeElement|nullيبحث في محتوى العنصر عن نمط النص المحدّد، بدءًا من نتيجة بحث معيّنة.
getAttributes()Objectيتم استرداد سمات العنصر.
getAttributes(offset)Objectتعرض هذه الطريقة السمات في موضع الإزاحة المحدّد للحرف.
getBackgroundColor()String|nullتعرض هذه السمة إعداد لون الخلفية.
getBackgroundColor(offset)String|nullتسترد لون الخلفية عند موضع الحرف المحدد.
getFontFamily()String|nullتعرض هذه السمة إعدادات مجموعة الخطوط.
getFontFamily(offset)String|nullتسترد مجموعة الخطوط عند الإزاحة المحدّدة للأحرف.
getFontSize()Number|nullتعرض هذه السمة إعدادات حجم الخط.
getFontSize(offset)Number|nullتسترد حجم الخط عند الإزاحة المحدّدة للحرف.
getForegroundColor()String|nullتعرض هذه السمة إعداد لون المقدّمة.
getForegroundColor(offset)String|nullتعرض هذه السمة لون المقدّمة عند موضع الحرف المحدّد.
getLinkUrl()String|nullتعرض هذه السمة عنوان URL للرابط.
getLinkUrl(offset)String|nullيستردّ عنوان URL للرابط عند موضع الإزاحة المحدّد للحرف.
getNextSibling()Element|nullيستردّ العنصر الشقيق التالي للعنصر.
getParent()ContainerElement|nullتعرض هذه السمة العنصر الرئيسي للعنصر الحالي.
getPreviousSibling()Element|nullيتم استرداد العنصر الشقيق السابق للعنصر.
getText()Stringتعرض محتوى العنصر كسلسلة نصية.
getTextAlignment()TextAlignment|nullتعرض هذه السمة محاذاة النص.
getTextAlignment(offset)TextAlignment|nullتعرض هذه السمة محاذاة النص لحرف واحد.
getTextAttributeIndices()Integer[]تعرض هذه السمة مجموعة فهارس النصوص التي تتوافق مع بداية عمليات تنسيق النصوص المميّزة.
getType()ElementTypeيستردّ ElementType الخاص بالعنصر.
insertText(offset, text)Textتُدرج هذه الطريقة النص المحدّد في موضع الإزاحة المحدّد للحرف.
isAtDocumentEnd()Booleanتحدّد هذه السمة ما إذا كان العنصر في نهاية Document.
isBold()Boolean|nullتعرض هذه السمة إعداد النص الغامق.
isBold(offset)Boolean|nullتسترد إعداد النص الغامق عند موضع الحرف المحدّد.
isItalic()Boolean|nullتعرض هذه السمة إعداد الخط المائل.
isItalic(offset)Boolean|nullتسترد إعداد الخط المائل عند إزاحة الحرف المحدّدة.
isStrikethrough()Boolean|nullتسترد إعداد النص المشطوب.
isStrikethrough(offset)Boolean|nullتسترد إعداد التشطيب عند موضع الحرف المحدّد.
isUnderline()Boolean|nullتعرض هذه السمة إعداد التسطير.
isUnderline(offset)Boolean|nullتعرض هذه الطريقة إعداد التسطير عند موضع الحرف المحدّد.
merge()Text|nullيدمج العنصر مع العنصر الشقيق السابق من النوع نفسه.
removeFromParent()Text|nullتزيل هذه الطريقة العنصر من العنصر الأصل.
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/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');

المَعلمات

الاسمالنوعالوصف
textStringالنص المطلوب إلحاقه

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
startOffsetIntegerإزاحة الحرف الأول المطلوب حذفه
endOffsetInclusiveIntegerإزاحة الحرف الأخير المطلوب حذفه

الإرجاع

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 بشكل كامل، مثل مجموعات الالتقاط ومعدّلات الوضع.

تتم مطابقة نمط التعبير العادي المقدَّم بشكل مستقل مع كل كتلة نصية مضمّنة في العنصر الحالي.

المَعلمات

الاسمالنوعالوصف
searchPatternStringالنمط المطلوب البحث عنه

الإرجاع

RangeElement|null — نتيجة بحث تشير إلى موضع نص البحث، أو قيمة فارغة إذا لم تكن هناك أي مطابقة

التفويض

تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:

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

findText(searchPattern, from)

يبحث في محتوى العنصر عن نمط النص المحدّد، بدءًا من نتيجة بحث معيّنة.

لا تتوافق مجموعة فرعية من ميزات التعبير العادي في JavaScript بشكل كامل، مثل مجموعات الالتقاط ومعدّلات الوضع.

تتم مطابقة نمط التعبير العادي المقدَّم بشكل مستقل مع كل كتلة نصية مضمّنة في العنصر الحالي.

المَعلمات

الاسمالنوعالوصف
searchPatternStringالنمط المطلوب البحث عنه
fromRangeElementنتيجة البحث التي تريد البحث منها

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
offsetIntegerإزاحة الحرف

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
offsetIntegerإزاحة الحرف

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
offsetIntegerإزاحة الحرف

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
offsetIntegerإزاحة الحرف

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
offsetIntegerإزاحة الحرف

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
offsetIntegerإزاحة الحرف

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
offsetIntegerإزاحة الحرف

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
offsetIntegerإزاحة الحرف الذي سيتم إدراج النص عنده.
textStringالنص المطلوب إدراجه

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
offsetIntegerإزاحة الحرف

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
offsetIntegerإزاحة الحرف

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
offsetIntegerإزاحة الحرف

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
offsetIntegerإزاحة الحرف

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
searchPatternStringنمط التعبير العادي المطلوب البحث عنه
replacementStringالنص الذي سيتم استخدامه كبديل

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
startOffsetIntegerإزاحة بداية نطاق النص
endOffsetInclusiveIntegerإزاحة نهاية نطاق النص
attributesObjectسمات العنصر

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
attributesObjectسمات العنصر

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
startOffsetIntegerإزاحة بداية نطاق النص
endOffsetInclusiveIntegerإزاحة نهاية نطاق النص
colorStringلون الخلفية، بتنسيق CSS (مثل '#ffffff')

الإرجاع

Text: العنصر الحالي

التفويض

تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:

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

setBackgroundColor(color)

تضبط هذه السمة لون الخلفية.

المَعلمات

الاسمالنوعالوصف
colorStringلون الخلفية، بتنسيق CSS (مثل '#ffffff')

الإرجاع

Text: العنصر الحالي

التفويض

تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:

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

setBold(bold)

تضبط هذه السمة إعداد النص الغامق.

المَعلمات

الاسمالنوعالوصف
boldBooleanإعداد النص الغامق

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
startOffsetIntegerإزاحة بداية نطاق النص
endOffsetInclusiveIntegerإزاحة نهاية نطاق النص
boldBooleanإعداد النص الغامق

الإرجاع

Text: العنصر الحالي

التفويض

تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:

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

setFontFamily(startOffset, endOffsetInclusive, fontFamilyName)

تضبط هذه السمة مجموعة الخطوط لنطاق الأحرف المحدّد. يمكن أن يكون الاسم أي خط من قائمة الخطوط في &quot;مستندات Google&quot; أو 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');

المَعلمات

الاسمالنوعالوصف
startOffsetIntegerإزاحة بداية نطاق النص
endOffsetInclusiveIntegerإزاحة نهاية نطاق النص
fontFamilyNameStringاسم مجموعة الخطوط، من قائمة "الخط" في "مستندات 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. على الرغم من أنّ هذا التعداد قد تم إيقافه نهائيًا، سيظل متاحًا لضمان التوافق مع النصوص البرمجية القديمة.

المَعلمات

الاسمالنوعالوصف
fontFamilyNameStringاسم مجموعة الخطوط، من قائمة "الخط" في "مستندات 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);

المَعلمات

الاسمالنوعالوصف
startOffsetIntegerإزاحة بداية نطاق النص
endOffsetInclusiveIntegerإزاحة نهاية نطاق النص
sizeNumberحجم الخط

الإرجاع

Text: العنصر الحالي

التفويض

تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:

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

setFontSize(size)

تضبط هذه السمة حجم الخط.

المَعلمات

الاسمالنوعالوصف
sizeNumberحجم الخط

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
startOffsetIntegerإزاحة بداية نطاق النص
endOffsetInclusiveIntegerإزاحة نهاية نطاق النص
colorStringلون المقدّمة، بتنسيق CSS (مثل '#ffffff')

الإرجاع

Text: العنصر الحالي

التفويض

تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:

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

setForegroundColor(color)

لضبط لون المقدّمة.

المَعلمات

الاسمالنوعالوصف
colorStringلون المقدّمة، بتنسيق CSS (مثل '#ffffff')

الإرجاع

Text: العنصر الحالي

التفويض

تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:

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

setItalic(italic)

تضبط هذه السمة إعداد الخط المائل.

المَعلمات

الاسمالنوعالوصف
italicBooleanإعداد الخط المائل

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
startOffsetIntegerإزاحة بداية نطاق النص
endOffsetInclusiveIntegerإزاحة نهاية نطاق النص
italicBooleanإعداد الخط المائل

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
startOffsetIntegerإزاحة بداية نطاق النص
endOffsetInclusiveIntegerإزاحة نهاية نطاق النص
urlStringتمثّل هذه السمة عنوان URL للرابط.

الإرجاع

Text: العنصر الحالي

التفويض

تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:

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

setLinkUrl(url)

يضبط عنوان URL للرابط.

المَعلمات

الاسمالنوعالوصف
urlStringعنوان URL للرابط

الإرجاع

Text: العنصر الحالي

التفويض

تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:

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

setStrikethrough(strikethrough)

تضبط هذه السمة إعداد النص المشطوب.

المَعلمات

الاسمالنوعالوصف
strikethroughBooleanإعداد النص المشطوب

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
startOffsetIntegerإزاحة بداية نطاق النص
endOffsetInclusiveIntegerإزاحة نهاية نطاق النص
strikethroughBooleanإعداد النص المشطوب

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
textStringمحتوى النص الجديد

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
startOffsetIntegerتمثّل هذه السمة إزاحة بداية نطاق الأحرف.
endOffsetInclusiveIntegerالإزاحة النهائية لنطاق الأحرف (شاملة).
textAlignmentTextAlignmentنوع محاذاة النص المطلوب تطبيقه.

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
textAlignmentTextAlignmentنوع محاذاة النص المطلوب تطبيقه

الإرجاع

Text: العنصر الحالي

التفويض

تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:

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

setUnderline(underline)

تضبط هذه السمة إعداد التسطير.

المَعلمات

الاسمالنوعالوصف
underlineBooleanإعداد التسطير

الإرجاع

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

المَعلمات

الاسمالنوعالوصف
startOffsetIntegerإزاحة بداية نطاق النص
endOffsetInclusiveIntegerإزاحة نهاية نطاق النص
underlineBooleanإعداد التسطير

الإرجاع

Text: العنصر الحالي

التفويض

تتطلّب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على إذن باستخدام نطاق واحد أو أكثر من النطاقات التالية:

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