Class Text

Text

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

المعلَمات

الاسمالنوعالوصف
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/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);

المعلَمات

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

تذكرة ذهاب وعودة

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)

للبحث في محتويات العنصر عن نمط النص المحدد باستخدام التعبيرات العادية.

هناك مجموعة فرعية من ميزات التعبير العادي في جافا سكريبت غير متوافقة بالكامل، مثل التقاط المجموعات ومُعدِّلات الوضع.

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

المعلَمات

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

تذكرة ذهاب وعودة

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

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:

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

findText(searchPattern, from)

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

هناك مجموعة فرعية من ميزات التعبير العادي في جافا سكريبت غير متوافقة بالكامل، مثل التقاط المجموعات ومُعدِّلات الوضع.

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

المعلَمات

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

تذكرة ذهاب وعودة

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

المعلَمات

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

تذكرة ذهاب وعودة

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

المعلَمات

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

تذكرة ذهاب وعودة

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

المعلَمات

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

تذكرة ذهاب وعودة

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

المعلَمات

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

تذكرة ذهاب وعودة

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

المعلَمات

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

تذكرة ذهاب وعودة

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

المعلَمات

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

تذكرة ذهاب وعودة

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

المعلَمات

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

تذكرة ذهاب وعودة

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

المعلَمات

الاسمالنوعالوصف
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 — سواء كان النص غامقًا أو خالٍ إذا كان العنصر يحتوي على قيم متعددة لهذه السمة

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:

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

المعلَمات

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

تذكرة ذهاب وعودة

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

المعلَمات

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

تذكرة ذهاب وعودة

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

المعلَمات

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

تذكرة ذهاب وعودة

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

المعلَمات

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

تذكرة ذهاب وعودة

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

المعلَمات

الاسمالنوعالوصف
searchPatternStringنمط regex للبحث عنه
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/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);

المعلَمات

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

تذكرة ذهاب وعودة

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

المعلَمات

الاسمالنوعالوصف
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/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');

المعلَمات

الاسمالنوعالوصف
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/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);

المعلَمات

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

تذكرة ذهاب وعودة

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

المعلَمات

الاسمالنوعالوصف
startOffsetIntegerإزاحة بداية نطاق النص.
endOffsetInclusiveIntegerإزاحة نهاية نطاق النص.
fontFamilyNameStringاسم مجموعة الخطوط، من قائمة الخطوط في "مستندات Google" أو "خطوط Google".

تذكرة ذهاب وعودة

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

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:

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

setFontFamily(fontFamilyName)

لتعيين مجموعة الخطوط. يمكن أن يكون الاسم بأي خط من قائمة الخطوط في المستندات أو خطوط Google، ويكون حساسًا لحالة الأحرف. سيتم عرض أسماء الخطوط غير المعروفة كـ Arial. تستخدم طريقتا getFontFamily() وsetFontFamily(fontFamilyName) الآن أسماء السلاسل للخطوط بدلاً من التعداد FontFamily. على الرغم من أنه تم إيقاف هذا التعداد، فسيتم الإبقاء عليه متوافقًا مع النصوص البرمجية القديمة.

المعلَمات

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

المعلَمات

الاسمالنوعالوصف
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/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);

المعلَمات

الاسمالنوعالوصف
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/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);

المعلَمات

الاسمالنوعالوصف
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/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');

المعلَمات

الاسمالنوعالوصف
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/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);

المعلَمات

الاسمالنوعالوصف
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/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.');

المعلَمات

الاسمالنوعالوصف
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 be superscript.
var text = DocumentApp.getActiveDocument().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 be superscript.
var text = DocumentApp.getActiveDocument().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/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);

المعلَمات

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

تذكرة ذهاب وعودة

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

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة تفويضًا باستخدام واحد أو أكثر من النطاقات التالية:

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