Class Table

جدول

عنصر يمثل جدولاً. لا يمكن أن يحتوي Table إلا على عناصر TableRow. لمزيد من المعلومات حول بنية المستند، يمكنك الاطلاع على دليل توسيع "مستندات Google".

عند إنشاء Table يحتوي على عدد كبير من الصفوف أو الخلايا، ننصحك بإنشائه من مصفوفة سلسلة، كما هو موضّح في المثال التالي.

var body = DocumentApp.getActiveDocument().getBody();

// Create a two-dimensional array containing the 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.
body.appendTable(cells);

الطُرق

الطريقةنوع الإرجاعوصف قصير
appendTableRow()TableRowتنشئ السمة TableRow الجديدة وتُلحِقها.
appendTableRow(tableRow)TableRowتُرفِق TableRow المحدّدة.
clear()Tableيمحو محتوى العنصر.
copy()Tableعرض نسخة عميقة ومنفصلة للعنصر الحالي.
editAsText()Textللحصول على نسخة Text من العنصر الحالي لتعديلها.
findElement(elementType)RangeElementيبحث في محتوى العنصر الخاص بعنصر تابع من النوع المحدّد.
findElement(elementType, from)RangeElementيبحث في محتوى العنصر عن عنصر تابع من النوع المحدّد، بدءًا من RangeElement المحدّد.
findText(searchPattern)RangeElementيبحث في محتوى العنصر لنمط النص المحدد باستخدام التعبيرات العادية.
findText(searchPattern, from)RangeElementيبحث في محتوى العنصر عن النمط النصي المحدّد، بدءًا من نتيجة بحث معيّنة.
getAttributes()Objectلاسترداد سمات العنصر.
getBorderColor()Stringاسترجاع لون الحدود.
getBorderWidth()Numberلاسترداد عرض الحدود، بالنقاط.
getCell(rowIndex, cellIndex)TableCellاسترداد TableCell في الصف وفهارس الخلايا المحدّدين
getChild(childIndex)Elementاسترداد العنصر الثانوي في الفهرس الفرعي المحدد.
getChildIndex(child)Integerاسترداد الفهرس الفرعي للعنصر الفرعي المحدّد
getColumnWidth(columnIndex)Numberلاسترداد عرض عمود الجدول المحدَّد، بالنقاط.
getLinkUrl()Stringاسترداد عنوان URL للرابط.
getNextSibling()Elementلاسترداد العنصر التالي التابع للعنصر.
getNumChildren()Integerاسترجاع عدد الأطفال
getNumRows()Integerاسترداد عدد TableRows
getParent()ContainerElementلاسترداد العنصر الرئيسي للعنصر.
getPreviousSibling()Elementلاسترداد العنصر شقيق سابق للعنصر.
getRow(rowIndex)TableRowاسترداد TableRow في فهرس الصف المحدد
getText()Stringاسترجاع محتوى العنصر كسلسلة نصية.
getTextAlignment()TextAlignmentللحصول على محاذاة النص.
getType()ElementTypeلاسترداد ElementType للعنصر.
insertTableRow(childIndex)TableRowتنشئ السمة TableRow الجديدة وتدرجها في الفهرس المحدّد.
insertTableRow(childIndex, tableRow)TableRowإدخال TableRow المحددة في الفهرس المحدد.
isAtDocumentEnd()Booleanتُحدِّد هذه السياسة ما إذا كان العنصر في نهاية Document.
removeChild(child)Tableإزالة العنصر الفرعي المحدّد
removeFromParent()Tableإزالة العنصر من العنصر الرئيسي
removeRow(rowIndex)TableRowتزيل TableRow في فهرس الصف المحدد.
replaceText(searchPattern, replacement)Elementيستبدل جميع تكرارات نمط نص معين بسلسلة بديلة معينة باستخدام التعبيرات العادية.
setAttributes(attributes)Tableتحدد سمات العنصر.
setBorderColor(color)Tableلضبط لون الحدود
setBorderWidth(width)Tableلضبط عرض الحدود بالنقاط.
setColumnWidth(columnIndex, width)Tableلضبط عرض العمود المحدّد، بالنقاط.
setLinkUrl(url)Tableلضبط عنوان URL للرابط.
setTextAlignment(textAlignment)Tableلضبط محاذاة النص.

المستندات التفصيلية

appendTableRow()

تنشئ السمة TableRow الجديدة وتُلحِقها.

رحلة العودة

TableRow - عنصر الصف الجديد في الجدول

التفويض

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

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

appendTableRow(tableRow)

تُرفِق TableRow المحدّدة.

// Opens the Docs file by its ID. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the ID with your own.
const doc = DocumentApp.openById('abc123456');

// Gets the document body.
const body = doc.getBody();

// Gets the first table in the document and copies the second row.
const table = body.getTables()[0];
const row = table.getChild(1).copy();

// Adds the copied row to the bottom of the table.
const tableRow = table.appendTableRow(row);

المَعلمات

الاسمالنوعالوصف
tableRowTableRowصف الجدول المطلوب إلحاقه.

رحلة العودة

TableRow — عنصر الصف المرفق في الجدول

التفويض

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

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

clear()

يمحو محتوى العنصر.

رحلة العودة

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


copy()

عرض نسخة عميقة ومنفصلة للعنصر الحالي.

يتم أيضًا نسخ أي عناصر فرعية موجودة في العنصر. لا يحتوي العنصر الجديد على عنصر رئيسي.

رحلة العودة

Table — النسخة الجديدة

التفويض

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

  • 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 — نسخة نصية من العنصر الحالي


findElement(elementType)

يبحث في محتوى العنصر الخاص بعنصر تابع من النوع المحدّد.

المَعلمات

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

رحلة العودة

RangeElement: نتيجة بحث تشير إلى موضع عنصر البحث

التفويض

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

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

findElement(elementType, from)

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

// Get the body section of the active document.
var body = DocumentApp.getActiveDocument().getBody();

// Define the search parameters.
var searchType = DocumentApp.ElementType.PARAGRAPH;
var searchHeading = DocumentApp.ParagraphHeading.HEADING1;
var searchResult = null;

// Search until the paragraph is found.
while (searchResult = body.findElement(searchType, searchResult)) {
  var par = searchResult.getElement().asParagraph();
  if (par.getHeading() == searchHeading) {
    // Found one, update and stop.
    par.setText('This is the first header.');
    return;
  }
}

المَعلمات

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

رحلة العودة

RangeElement: نتيجة بحث تشير إلى الموضع التالي لعنصر البحث

التفويض

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

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

findText(searchPattern)

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

هناك مجموعة فرعية من ميزات التعبير العادي في JavaScript غير متوافقة بالكامل، مثل مجموعات الالتقاط ومفاتيح تعديل الأوضاع.

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

المَعلمات

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

رحلة العودة

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

التفويض

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

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

findText(searchPattern, from)

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

هناك مجموعة فرعية من ميزات التعبير العادي في JavaScript غير متوافقة بالكامل، مثل مجموعات الالتقاط ومفاتيح تعديل الأوضاع.

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

المَعلمات

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

getBorderColor()

استرجاع لون الحدود.

// Opens the Docs file by its ID. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the ID with your own.
const doc = DocumentApp.openById('abc123456');

// Gets the document body.
const body = doc.getBody();

// Gets the first table.
const table = body.getTables()[0];

// Sets the border color of the first table.
table.setBorderColor('#00FF00');

// Logs the border color of the first table to the console.
console.log(table.getBorderColor());

رحلة العودة

String: لون الحدّ منسَّق في تدوين CSS (مثل '#ffffff').

التفويض

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

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

getBorderWidth()

لاسترداد عرض الحدود، بالنقاط.

// Opens the Docs file by its ID. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the ID with your own.
const doc = DocumentApp.openById('abc123456');

// Gets the document body.
const body = doc.getBody();

// Gets the first table.
const table = body.getTables()[0];

// Sets the border width of the first table.
table.setBorderWidth(20);

// Logs the border width of the first table.
console.log(table.getBorderWidth());

رحلة العودة

Number: عرض الحدود بالنقاط.

التفويض

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

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

getCell(rowIndex, cellIndex)

استرداد TableCell في الصف وفهارس الخلايا المحدّدين

// Opens the Docs file by its ID. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the ID with your own.
const doc = DocumentApp.openById('abc123456');

// Gets the document body.
const body = doc.getBody();

// Gets the first table.
const table = body.getTables()[0];

// Gets the cell of the table's third row and second column.
const cell = table.getCell(2, 1);

// Logs the cell text to the console.
console.log(cell.getText());

المَعلمات

الاسمالنوعالوصف
rowIndexIntegerفهرس الصف الذي يحتوي على الخلية المطلوب استردادها.
cellIndexIntegerفهرس الخلية المراد استردادها

رحلة العودة

TableCell - خلية الجدول

التفويض

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

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

getChild(childIndex)

استرداد العنصر الثانوي في الفهرس الفرعي المحدد.

// Get the body section of the active document.
var body = DocumentApp.getActiveDocument().getBody();

// Obtain the first element in the document.
var firstChild = body.getChild(0);

// If it's a paragraph, set its contents.
if (firstChild.getType() == DocumentApp.ElementType.PARAGRAPH) {
  firstChild.asParagraph().setText("This is the first paragraph.");
}

المَعلمات

الاسمالنوعالوصف
childIndexIntegerفهرس العنصر الثانوي المطلوب استرداده

رحلة العودة

Element: العنصر الثانوي في الفهرس المحدَّد

التفويض

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

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

getChildIndex(child)

استرداد الفهرس الفرعي للعنصر الفرعي المحدّد

المَعلمات

الاسمالنوعالوصف
childElementالعنصر الثانوي الذي يجب استرداد الفهرس له

رحلة العودة

Integer: الفهرس الفرعي

التفويض

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

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

getColumnWidth(columnIndex)

لاسترداد عرض عمود الجدول المحدَّد، بالنقاط.

// Opens the Docs file by its ID. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the ID with your own.
const doc = DocumentApp.openById('abc123456');

// Gets the document body.
const body = doc.getBody();

// Gets the first table.
const table = body.getTables()[0];

// Sets the width of the second column to 100 points.
const columnWidth = table.setColumnWidth(1, 100);

// Gets the width of the second column and logs it to the console.
console.log(columnWidth.getColumnWidth(1));

المَعلمات

الاسمالنوعالوصف
columnIndexIntegerفهرس العمود

رحلة العودة

Number: عرض العمود بالنقاط.

التفويض

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

  • 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

getNextSibling()

لاسترداد العنصر التالي التابع للعنصر.

العنصر الرئيسي التالي له العنصر الرئيسي نفسه ويتّبع العنصر الحالي.

رحلة العودة

Element: العنصر المقابل التالي

التفويض

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

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

getNumChildren()

استرجاع عدد الأطفال

// Get the body section of the active document.
var body = DocumentApp.getActiveDocument().getBody();

// Log the number of elements in the document.
Logger.log("There are " + body.getNumChildren() +
    " elements in the document body.");

رحلة العودة

Integer - عدد الأطفال

التفويض

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

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

getNumRows()

استرداد عدد TableRows

// Opens the Docs file by its ID. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the ID with your own.
const doc = DocumentApp.openById('abc123456');

// Gets the document body.
const body = doc.getBody();

// Gets the first table.
const table = body.getTables()[0];

// Logs the number of rows of the first table to the console.
console.log(table.getNumRows());

رحلة العودة

Integer: عدد صفوف الجدول.

التفويض

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

  • 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

getRow(rowIndex)

استرداد TableRow في فهرس الصف المحدد

// Opens the Docs file by its ID. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the ID with your own.
const doc = DocumentApp.openById('abc123456');

// Gets the document body.
const body = doc.getBody();

// Gets the first table and logs the text of first row to the console.
const table = body.getTables()[0];
console.log(table.getRow(0).getText());

المَعلمات

الاسمالنوعالوصف
rowIndexIntegerفهرس الصف المطلوب استرداده.

رحلة العودة

TableRow - صف الجدول.

التفويض

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

  • 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

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

insertTableRow(childIndex)

تنشئ السمة TableRow الجديدة وتدرجها في الفهرس المحدّد.

المَعلمات

الاسمالنوعالوصف
childIndexIntegerالفهرس الذي يجب إدراج العنصر فيه

رحلة العودة

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

التفويض

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

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

insertTableRow(childIndex, tableRow)

إدخال TableRow المحددة في الفهرس المحدد.

المَعلمات

الاسمالنوعالوصف
childIndexIntegerالفهرس الذي يجب إدراج العنصر فيه
tableRowTableRowصف الجدول المطلوب إدراجه

رحلة العودة

TableRow — عنصر صف الجدول الذي تم إدراجه

التفويض

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

  • 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

removeChild(child)

إزالة العنصر الفرعي المحدّد

// Opens the Docs file by its ID. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the ID with your own.
const doc = DocumentApp.openById('abc123456');

// Gets the document body.
const body = doc.getBody();

// Gets the first table.
const table = body.getTables()[0];

// Finds the first table row and removes it.
const element = table.findElement(DocumentApp.ElementType.TABLE_ROW);
table.removeChild(element.getElement());

المَعلمات

الاسمالنوعالوصف
childElementالعنصر الفرعي المطلوب إزالته

رحلة العودة

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

التفويض

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

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

رحلة العودة

Table — العنصر الذي تمت إزالته

التفويض

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

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

removeRow(rowIndex)

تزيل TableRow في فهرس الصف المحدد.

// Opens the Docs file by its ID. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the ID with your own.
const doc = DocumentApp.openById('abc123456');

// Gets the document body.
const body = doc.getBody();

// Gets the first table and removes its second row.
const table = body.getTables()[0];
table.removeRow(1);

المَعلمات

الاسمالنوعالوصف
rowIndexIntegerفهرس الصف المطلوب إزالته.

رحلة العودة

TableRow: الصف الذي تمت إزالته

التفويض

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

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

replaceText(searchPattern, replacement)

يستبدل جميع تكرارات نمط نص معين بسلسلة بديلة معينة باستخدام التعبيرات العادية.

يتم تمرير نمط البحث كسلسلة، وليس كعنصر تعبير عادي في JavaScript. لهذا السبب، عليك تجنُّب أي شرطة مائلة للخلف في النمط.

وتستخدِم هذه الطرق مكتبة التعبير العادي RE2 التي تفرض قيودًا على البنية المتوافقة.

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

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(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سمات العنصر.

رحلة العودة

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

التفويض

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

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

setBorderColor(color)

لضبط لون الحدود

// Opens the Docs file by its ID. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the ID with your own.
const doc = DocumentApp.openById('abc123456');

// Gets the document body.
const body = doc.getBody();

// Gets the first table.
const table = body.getTables()[0];

// Sets the border color of the table to green.
table.setBorderColor('#00FF00');

المَعلمات

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

رحلة العودة

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

التفويض

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

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

setBorderWidth(width)

لضبط عرض الحدود بالنقاط.

المَعلمات

الاسمالنوعالوصف
widthNumberعرض الحدود، بالنقاط

رحلة العودة

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

التفويض

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

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

setColumnWidth(columnIndex, width)

لضبط عرض العمود المحدّد، بالنقاط.

المَعلمات

الاسمالنوعالوصف
columnIndexIntegerفهرس العمود
widthNumberعرض الحدود، بالنقاط

رحلة العودة

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

التفويض

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

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

setLinkUrl(url)

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

المَعلمات

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

رحلة العودة

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

التفويض

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

  • 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نوع محاذاة النص الذي سيتم تطبيقه

رحلة العودة

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

التفويض

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

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