Class Table

میز

عنصری که نمایانگر یک جدول است. یک Table فقط می‌تواند شامل عناصر Table Row باشد. برای اطلاعات بیشتر در مورد ساختار سند، به راهنمای توسعه Google Docs مراجعه کنید.

هنگام ایجاد 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);

روش‌ها

روش نوع بازگشتی شرح مختصر
append Table Row() Table Row یک Table Row جدید ایجاد و اضافه می‌کند.
append Table Row(tableRow) Table Row Table Row داده شده را اضافه می‌کند.
clear() Table محتویات عنصر را پاک می‌کند.
copy() Table یک کپی جدا و عمیق از عنصر فعلی را برمی‌گرداند.
edit As Text() Text یک نسخه Text از عنصر فعلی را برای ویرایش دریافت می‌کند.
find Element(elementType) Range Element |null محتویات عنصر را برای یافتن نسلی از نوع مشخص شده جستجو می‌کند.
find Element(elementType, from) Range Element |null محتویات عنصر را برای یافتن نسلی از نوع مشخص شده، با شروع از Range Element مشخص شده، جستجو می‌کند.
find Text(searchPattern) Range Element |null با استفاده از عبارات منظم، محتوای عنصر را برای الگوی متنی مشخص شده جستجو می‌کند.
find Text(searchPattern, from) Range Element |null با شروع از یک نتیجه جستجوی داده شده، محتویات عنصر را برای الگوی متنی مشخص شده جستجو می‌کند.
get Attributes() Object ویژگی‌های عنصر را بازیابی می‌کند.
get Border Color() String|null رنگ حاشیه را بازیابی می‌کند.
get Border Width() Number|null عرض حاشیه را بر حسب نقطه برمی‌گرداند.
get Cell(rowIndex, cellIndex) Table Cell |null Table Cell در ردیف و شاخص‌های سلول مشخص شده بازیابی می‌کند.
get Child(childIndex) Element عنصر فرزند را در اندیس فرزند مشخص شده بازیابی می‌کند.
get Child Index(child) Integer اندیس فرزند را برای عنصر فرزند مشخص شده بازیابی می‌کند.
get Column Width(columnIndex) Number|null عرض ستون جدول مشخص شده را بر حسب نقطه برمی‌گرداند.
get Link Url() String|null آدرس لینک را بازیابی می‌کند.
get Next Sibling() Element |null عنصر خواهر یا برادر بعدی عنصر را بازیابی می‌کند.
get Num Children() Integer تعداد فرزندان را بازیابی می‌کند.
get Num Rows() Integer تعداد Table Rows را بازیابی می‌کند.
get Parent() Container Element |null عنصر والد عنصر را بازیابی می‌کند.
get Previous Sibling() Element |null عنصر خواهر و برادر قبلی عنصر را بازیابی می‌کند.
get Row(rowIndex) Table Row |null Table Row را در اندیس سطر مشخص شده بازیابی می‌کند.
get Text() String محتوای عنصر را به صورت یک رشته متنی بازیابی می‌کند.
get Text Alignment() Text Alignment |null ترازبندی متن را دریافت می‌کند.
get Type() Element Type Element Type را بازیابی می‌کند.
insert Table Row(childIndex) Table Row یک Table Row جدید را در فهرست مشخص شده ایجاد و درج می‌کند.
insert Table Row(childIndex, tableRow) Table Row Table Row داده شده را در اندیس مشخص شده درج می‌کند.
is At Document End() Boolean تعیین می‌کند که آیا عنصر در انتهای Document قرار دارد یا خیر.
remove Child(child) Table عنصر فرزند مشخص شده را حذف می‌کند.
remove From Parent() Table |null عنصر را از والدش حذف می‌کند.
remove Row(rowIndex) Table Row Table Row را در اندیس ردیف مشخص شده حذف می‌کند.
replace Text(searchPattern, replacement) Element با استفاده از عبارات منظم، تمام موارد تکرار یک الگوی متنی مشخص را با یک رشته جایگزین مشخص جایگزین می‌کند.
set Attributes(attributes) Table ویژگی‌های عنصر را تنظیم می‌کند.
set Border Color(color) Table رنگ حاشیه را تنظیم می‌کند.
set Border Width(width) Table عرض حاشیه را بر حسب نقطه تنظیم می‌کند.
set Column Width(columnIndex, width) Table عرض ستون مشخص شده را بر حسب نقطه تنظیم می‌کند.
set Link Url(url) Table آدرس لینک را تنظیم می‌کند.
set Text Alignment(textAlignment) Table ترازبندی متن را تنظیم می‌کند.

مستندات دقیق

append Table Row()

یک Table Row جدید ایجاد و اضافه می‌کند.

بازگشت

Table Row - عنصر جدید ردیف جدول

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

append Table Row(tableRow)

Table Row داده شده را اضافه می‌کند.

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

پارامترها

نام نوع توضیحات
table Row Table Row ردیف جدولی که قرار است اضافه شود.

بازگشت

Table Row - عنصر ردیف جدول اضافه شده.

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

  • 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

edit As Text()

یک نسخه Text از عنصر فعلی را برای ویرایش دریافت می‌کند.

edit As Text برای دستکاری محتوای عناصر به عنوان متن غنی استفاده کنید. حالت edit As Text عناصر غیر متنی (مانند Inline Image و Horizontal Rule ) را نادیده می‌گیرد.

عناصر فرزندی که کاملاً در محدوده متن حذف شده قرار دارند، از عنصر حذف می‌شوند.

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 - نسخه متنی عنصر فعلی


find Element(elementType)

محتویات عنصر را برای یافتن نسلی از نوع مشخص شده جستجو می‌کند.

پارامترها

نام نوع توضیحات
element Type Element Type نوع عنصری که باید جستجو شود.

بازگشت

Range Element |null — نتیجه جستجو که موقعیت عنصر جستجو را نشان می‌دهد.

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

find Element(elementType, from)

محتویات عنصر را برای یافتن نسلی از نوع مشخص شده، با شروع از Range Element مشخص شده، جستجو می‌کند.

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

پارامترها

نام نوع توضیحات
element Type Element Type نوع عنصری که باید جستجو شود.
from Range Element نتیجه جستجو برای جستجو از.

بازگشت

Range Element |null — نتیجه جستجو که موقعیت بعدی عنصر جستجو را نشان می‌دهد.

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

find Text(searchPattern)

با استفاده از عبارات منظم، محتوای عنصر را برای الگوی متنی مشخص شده جستجو می‌کند.

زیرمجموعه‌ای از ویژگی‌های عبارات منظم جاوا اسکریپت به طور کامل پشتیبانی نمی‌شوند، مانند گروه‌های ضبط و اصلاح‌کننده‌های حالت.

الگوی عبارت منظم ارائه شده به طور مستقل با هر بلوک متنی موجود در عنصر فعلی مطابقت داده می‌شود.

پارامترها

نام نوع توضیحات
search Pattern String الگویی که باید جستجو شود

بازگشت

Range Element |null — نتیجه جستجو که موقعیت متن جستجو را نشان می‌دهد، یا در صورت عدم تطابق، null

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

find Text(searchPattern, from)

با شروع از یک نتیجه جستجوی داده شده، محتویات عنصر را برای الگوی متنی مشخص شده جستجو می‌کند.

زیرمجموعه‌ای از ویژگی‌های عبارات منظم جاوا اسکریپت به طور کامل پشتیبانی نمی‌شوند، مانند گروه‌های ضبط و اصلاح‌کننده‌های حالت.

الگوی عبارت منظم ارائه شده به طور مستقل با هر بلوک متنی موجود در عنصر فعلی مطابقت داده می‌شود.

پارامترها

نام نوع توضیحات
search Pattern String الگویی که باید جستجو شود
from Range Element نتیجه جستجو برای جستجو از

بازگشت

Range Element |null — نتیجه جستجو که موقعیت بعدی متن جستجو را نشان می‌دهد، یا در صورت عدم تطابق، null است.

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

get Attributes()

ویژگی‌های عنصر را بازیابی می‌کند.

نتیجه، یک شیء حاوی یک ویژگی برای هر ویژگی عنصر معتبر است که در آن هر نام ویژگی با یک آیتم در شمارش Document App.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

get Border 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 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

get Border Width()

عرض حاشیه را بر حسب نقطه برمی‌گرداند.

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

get Cell(rowIndex, cellIndex)

Table Cell در ردیف و شاخص‌های سلول مشخص شده بازیابی می‌کند.

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

پارامترها

نام نوع توضیحات
row Index Integer اندیس ردیفی که سلول مورد نظر برای بازیابی در آن قرار دارد.
cell Index Integer اندیس سلولی که قرار است بازیابی شود.

بازگشت

Table Cell |null — سلول جدول.

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

get Child(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.');
}

پارامترها

نام نوع توضیحات
child Index Integer اندیس عنصر فرزندی که قرار است بازیابی شود.

بازگشت

Element - عنصر فرزند در اندیس مشخص شده.

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

get Child Index(child)

اندیس فرزند را برای عنصر فرزند مشخص شده بازیابی می‌کند.

پارامترها

نام نوع توضیحات
child Element عنصر فرزندی که اندیس آن بازیابی می‌شود.

بازگشت

Integer - اندیس فرزند.

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

get Column Width(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));

پارامترها

نام نوع توضیحات
column Index Integer شاخص ستون.

بازگشت

Number|null — عرض ستون، بر حسب نقطه.

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

get Link Url()

آدرس لینک را بازیابی می‌کند.

بازگشت

String|null — آدرس اینترنتی لینک، یا اگر عنصر شامل چندین مقدار برای این ویژگی باشد، null.

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

get Next Sibling()

عنصر خواهر یا برادر بعدی عنصر را بازیابی می‌کند.

خواهر یا برادر بعدی، والد یکسانی دارد و عنصر فعلی را دنبال می‌کند.

بازگشت

Element |null — عنصر خواهر یا برادر بعدی.

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

get Num Children()

تعداد فرزندان را بازیابی می‌کند.

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

get Num Rows()

تعداد Table Rows را بازیابی می‌کند.

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

get Parent()

عنصر والد عنصر را بازیابی می‌کند.

عنصر والد شامل عنصر فعلی است.

بازگشت

Container Element |null — عنصر والد.

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

get Previous Sibling()

عنصر خواهر و برادر قبلی عنصر را بازیابی می‌کند.

عنصر خواهر یا برادر قبلی، والد یکسانی دارد و قبل از عنصر فعلی قرار می‌گیرد.

بازگشت

Element |null — عنصر خواهر یا برادر قبلی.

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

get Row(rowIndex)

Table Row را در اندیس سطر مشخص شده بازیابی می‌کند.

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

پارامترها

نام نوع توضیحات
row Index Integer اندیس ردیفی که قرار است بازیابی شود.

بازگشت

Table Row |null — سطر جدول.

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

get Text()

محتوای عنصر را به صورت یک رشته متنی بازیابی می‌کند.

بازگشت

String - محتویات عنصر به صورت رشته متنی

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

get Text Alignment()

ترازبندی متن را دریافت می‌کند. انواع ترازبندی موجود عبارتند از Document App.TextAlignment.NORMAL ، Document App.TextAlignment.SUBSCRIPT و Document App.TextAlignment.SUPERSCRIPT .

بازگشت

Text Alignment |null — نوع ترازبندی متن، یا اگر متن شامل چندین نوع ترازبندی متن باشد یا ترازبندی متن هرگز تنظیم نشده باشد، null

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

get Type()

Element Type را بازیابی می‌کند.

برای تعیین نوع دقیق یک عنصر داده شده، get Type() استفاده کنید.

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

بازگشت

Element Type - نوع عنصر.

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

insert Table Row(childIndex)

یک Table Row جدید را در فهرست مشخص شده ایجاد و درج می‌کند.

پارامترها

نام نوع توضیحات
child Index Integer اندیسی که عنصر در آن قرار می‌گیرد

بازگشت

Table Row - عنصر فعلی

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

insert Table Row(childIndex, tableRow)

Table Row داده شده را در اندیس مشخص شده درج می‌کند.

پارامترها

نام نوع توضیحات
child Index Integer اندیسی که عنصر در آن قرار می‌گیرد
table Row Table Row ردیف جدول برای درج

بازگشت

Table Row - عنصر ردیف جدول درج شده

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

is At Document End()

تعیین می‌کند که آیا عنصر در انتهای Document قرار دارد یا خیر.

بازگشت

Boolean - اینکه آیا عنصر در انتهای تب قرار دارد یا خیر.

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

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

پارامترها

نام نوع توضیحات
child Element عنصر فرزندی که قرار است حذف شود.

بازگشت

Table - عنصر فعلی.

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

remove From Parent()

عنصر را از والدش حذف می‌کند.

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

remove Row(rowIndex)

Table Row را در اندیس ردیف مشخص شده حذف می‌کند.

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

پارامترها

نام نوع توضیحات
row Index Integer اندیس سطری که قرار است حذف شود.

بازگشت

Table Row — ردیف حذف شده.

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

replace Text(searchPattern, replacement)

با استفاده از عبارات منظم، تمام موارد تکرار یک الگوی متنی مشخص را با یک رشته جایگزین مشخص جایگزین می‌کند.

الگوی جستجو به صورت یک رشته ارسال می‌شود، نه یک شیء عبارت منظم جاوا اسکریپت. به همین دلیل، باید هرگونه بک‌اسلش را در الگو escape کنید.

این روش از کتابخانه عبارات منظم RE2 گوگل استفاده می‌کند که سینتکس‌های پشتیبانی‌شده را محدود می‌کند.

الگوی عبارت منظم ارائه شده به طور مستقل با هر بلوک متنی موجود در عنصر فعلی مطابقت داده می‌شود.

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

// Clear the text surrounding "Apps Script", with or without text.
body.replaceText('^.*Apps ?Script.*$', 'Apps Script');

پارامترها

نام نوع توضیحات
search Pattern String الگوی regex برای جستجو
replacement String متنی که قرار است به عنوان جایگزین استفاده شود

بازگشت

Element - عنصر فعلی

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

set Attributes(attributes)

ویژگی‌های عنصر را تنظیم می‌کند.

پارامتر ویژگی‌های مشخص‌شده باید یک شیء باشد که در آن نام هر ویژگی، یک آیتم در شمارش Document App.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);

پارامترها

نام نوع توضیحات
attributes Object ویژگی‌های عنصر.

بازگشت

Table - عنصر فعلی.

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

set Border Color(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');

پارامترها

نام نوع توضیحات
color String رنگ حاشیه، که با نمادگذاری CSS قالب‌بندی شده است (مانند '#ffffff' ).

بازگشت

Table - عنصر فعلی.

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

set Border Width(width)

عرض حاشیه را بر حسب نقطه تنظیم می‌کند.

پارامترها

نام نوع توضیحات
width Number عرض حاشیه، بر حسب نقطه

بازگشت

Table - عنصر فعلی

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

set Column Width(columnIndex, width)

عرض ستون مشخص شده را بر حسب نقطه تنظیم می‌کند.

پارامترها

نام نوع توضیحات
column Index Integer شاخص ستون
width Number عرض حاشیه، بر حسب نقطه

بازگشت

Table - عنصر فعلی

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

set Link Url(url)

آدرس لینک را تنظیم می‌کند.

پارامترها

نام نوع توضیحات
url String آدرس لینک

بازگشت

Table - عنصر فعلی

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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

set Text Alignment(textAlignment)

ترازبندی متن را تنظیم می‌کند. انواع ترازبندی موجود عبارتند از Document App.TextAlignment.NORMAL ، Document App.TextAlignment.SUBSCRIPT و Document App.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);

پارامترها

نام نوع توضیحات
text Alignment Text Alignment نوع ترازبندی متن که باید اعمال شود

بازگشت

Table - عنصر فعلی

مجوز

اسکریپت‌هایی که از این روش استفاده می‌کنند، نیاز به مجوز با یک یا چند مورد از حوزه‌های زیر دارند:

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