Class Table

جدول

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

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

const body =
    DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody();

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

الطُرق

الطريقةنوع القيمة التي يتم إرجاعهاوصف قصير
appendTableRow()TableRowتنشئ هذه السمة TableRow جديدة وتلحقها.
appendTableRow(tableRow)TableRowتُلحق هذه السمة TableRow المحدّدة.
clear()Tableيمحو محتوى العنصر.
copy()Tableتعرض نسخة منفصلة وعميقة من العنصر الحالي.
editAsText()Textيحصل على نسخة Text من العنصر الحالي لتعديلها.
findElement(elementType)RangeElement|nullيبحث في محتوى العنصر عن عنصر فرعي من النوع المحدّد.
findElement(elementType, from)RangeElement|nullيبحث في محتويات العنصر عن عنصر فرعي من النوع المحدّد، بدءًا من RangeElement المحدّد.
findText(searchPattern)RangeElement|nullيبحث في محتوى العنصر عن نمط النص المحدّد باستخدام التعبيرات العادية.
findText(searchPattern, from)RangeElement|nullيبحث في محتوى العنصر عن نمط النص المحدّد، بدءًا من نتيجة بحث معيّنة.
getAttributes()Objectيستردّ سمات العنصر.
getBorderColor()String|nullتعرض هذه السمة لون الحدود.
getBorderWidth()Number|nullتعرض هذه السمة عرض الحدود بالنقاط.
getCell(rowIndex, cellIndex)TableCell|nullتسترد هذه الدالة TableCell في فهرسَي الصف والخلية المحدّدين.
getChild(childIndex)Elementيستردّ العنصر الفرعي في فهرس العنصر الفرعي المحدّد.
getChildIndex(child)Integerيستردّ هذا الإجراء فهرس العنصر الفرعي للعنصر الفرعي المحدّد.
getColumnWidth(columnIndex)Number|nullتعرض هذه الدالة عرض عمود الجدول المحدّد بالنقاط.
getLinkUrl()String|nullتعرض هذه السمة عنوان URL للرابط.
getNextSibling()Element|nullيستردّ العنصر الشقيق التالي للعنصر.
getNumChildren()Integerتعرض هذه السمة عدد الأطفال.
getNumRows()Integerتعرض عدد TableRows.
getParent()ContainerElement|nullتعرض هذه السمة العنصر الرئيسي للعنصر الحالي.
getPreviousSibling()Element|nullيستردّ هذا الإجراء العنصر الشقيق السابق للعنصر.
getRow(rowIndex)TableRow|nullتعرض TableRow في فهرس الصف المحدّد.
getText()Stringتعرض محتوى العنصر كسلسلة نصية.
getTextAlignment()TextAlignment|nullتعرض هذه السمة محاذاة النص.
getType()ElementTypeيستردّ ElementType العنصر.
insertTableRow(childIndex)TableRowتُنشئ هذه الطريقة عنصر TableRow جديدًا وتُدرجه في الفهرس المحدّد.
insertTableRow(childIndex, tableRow)TableRowتُدرِج هذه الدالة القيمة TableRow المحدّدة في الفهرس المحدّد.
isAtDocumentEnd()Booleanتحدّد هذه السمة ما إذا كان العنصر في نهاية Document.
removeChild(child)Tableيزيل العنصر الفرعي المحدّد.
removeFromParent()Table|nullيزيل العنصر من العنصر الأصل.
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('123abc');

// 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 first table in the tab 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).

تتم إزالة العناصر الفرعية التي يتم تضمينها بالكامل في نطاق نص محذوف من العنصر.

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


findElement(elementType)

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

المعلمات

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

الإرجاع

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

التفويض

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

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

findElement(elementType, from)

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

const body =
    DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody();

// Define the search parameters.

let searchResult = null;

// Search until the paragraph is found.
while (
    (searchResult = body.findElement(
         DocumentApp.ElementType.PARAGRAPH,
         searchResult,
         ))) {
  const par = searchResult.getElement().asParagraph();
  if (par.getHeading() === DocumentApp.ParagraphHeading.HEADING1) {
    // Found one, update and stop.
    par.setText('This is the first header.');
    break;
  }
}

المعلمات

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

الإرجاع

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

التفويض

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

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

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

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('123abc');

// 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 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|null: لون الحد، بتنسيق 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('123abc');

// 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 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|null: تمثّل هذه السمة عرض الحدود بالنقاط.

التفويض

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

  • 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('123abc');

// 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 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|null: خلية الجدول

التفويض

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

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

getChild(childIndex)

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

const body =
    DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody();

// Obtain the first element in the tab.
const 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('123abc');

// 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 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|null: تمثّل عرض العمود بالنقاط.

التفويض

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

  • 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

getNextSibling()

يستردّ العنصر الشقيق التالي للعنصر.

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

الإرجاع

Element|null: العنصر الشقيق التالي

التفويض

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

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

getNumChildren()

تعرض هذه السمة عدد الأطفال.

const body =
    DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody();

// Log the number of elements in the tab.
Logger.log(`There are ${body.getNumChildren()} elements in the tab's 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('123abc');

// 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 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|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

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('123abc');

// 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 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|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

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

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('123abc');

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

يزيل العنصر من العنصر الأصل.

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

الإرجاع

Table|null: العنصر الذي تمت إزالته

التفويض

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

  • 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('123abc');

// 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 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 للتعبيرات العادية من 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(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سمات العنصر

الإرجاع

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('123abc');

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

الإرجاع

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

التفويض

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

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