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

Methods

メソッド戻り値の型概要
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()IntegerTableRows の数を取得します。
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 - 新しいテーブル行の要素

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • 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 - 追加のテーブル行の要素。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

clear()

要素の内容をクリアします。

リターン

Table - 現在の要素


copy()

現在の要素の分離されたディープコピーを返します。

その要素内にある子要素もコピーされます。新しい要素には親がありません。

リターン

Table - 新しいコピー。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

editAsText()

現在の要素の Text バージョンを取得し、編集します。

要素のコンテンツをリッチテキストとして操作するには、editAsText を使用します。editAsText モードでは、テキスト以外の要素(InlineImageHorizontalRule など)は無視されます。

削除したテキスト範囲内に完全に含まれる子要素は、要素から削除されます。

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 - 検索要素の位置を示す検索結果

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • 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 - 検索要素の次の位置を示す検索結果

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

findText(searchPattern)

正規表現を使用して、指定されたテキスト パターンについて要素の内容を検索します。

JavaScript の正規表現機能のサブセット(キャプチャ グループやモード修飾子など)は完全にはサポートされていません。

指定された正規表現パターンは、現在の要素に含まれている各テキスト ブロックと個別に照合されます。

パラメータ

名前説明
searchPatternString検索するパターンを指定します

リターン

RangeElement - 検索テキストの位置を示す検索結果。一致するものがない場合は null

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

findText(searchPattern, from)

指定された検索結果から、指定されたテキスト パターンの要素コンテンツを検索します。

JavaScript の正規表現機能のサブセット(キャプチャ グループやモード修飾子など)は完全にはサポートされていません。

指定された正規表現パターンは、現在の要素に含まれている各テキスト ブロックと個別に照合されます。

パラメータ

名前説明
searchPatternString検索するパターンを指定します
fromRangeElementクリックします。

リターン

RangeElement - 検索テキストの次の位置を示す検索結果。一致するものがない場合は null

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • 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 - 要素の属性。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • 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' など)で指定します。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • 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 - 枠線の太さ(ポイント単位)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • 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 - 表のセル。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • 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 - 指定されたインデックスの子要素

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getChildIndex(child)

指定された子要素の子インデックスを取得します。

パラメータ

名前説明
childElementインデックスを取得する子要素です

リターン

Integer - 子インデックス

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • 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 - 列の幅(ポイント単位)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getLinkUrl()

リンクの URL を取得します。

リターン

String - リンクの URL。要素内にこの属性に複数の値が含まれている場合は null。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getNextSibling()

要素の次の兄弟要素を取得します。

次の兄弟要素は同じ親を持ち、現在の要素をフォローします。

リターン

Element - 次の兄弟要素。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • 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 - 子の数

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • 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 - テーブルの行数。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getParent()

要素の親要素を取得します。

親要素には現在の要素が含まれます。

リターン

ContainerElement - 親要素。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getPreviousSibling()

要素の前の兄弟要素を取得します。

前の兄弟要素は同じ親を持ち、現在の要素の前にあります。

リターン

Element - 前の兄弟要素。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • 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 - テーブルの行。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getText()

要素のコンテンツをテキスト文字列として取得します。

リターン

String - 要素のコンテンツ(テキスト文字列)

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getTextAlignment()

テキストの配置を取得します。使用可能なアライメントのタイプは、DocumentApp.TextAlignment.NORMALDocumentApp.TextAlignment.SUBSCRIPTDocumentApp.TextAlignment.SUPERSCRIPT です。

リターン

TextAlignment - テキストの配置のタイプ。テキストに複数の種類のテキストの配置が含まれる場合、またはテキストの配置が設定されていない場合は null

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • 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 - 要素のタイプ。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

insertTableRow(childIndex)

指定されたインデックスに新しい TableRow を作成して挿入します。

パラメータ

名前説明
childIndexInteger要素を挿入するインデックス

リターン

TableRow - 現在の要素

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

insertTableRow(childIndex, tableRow)

指定された TableRow を指定されたインデックスに挿入します。

パラメータ

名前説明
childIndexInteger要素を挿入するインデックス
tableRowTableRow挿入するテーブルの行です。

リターン

TableRow - 挿入されるテーブル行の要素

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

isAtDocumentEnd()

要素が Document の末尾にあるかどうかを判断します。

リターン

Boolean - 要素がドキュメントの末尾にあるかどうか。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • 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 - 現在の要素。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • 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 - 削除された要素。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • 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 - 削除された行。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

replaceText(searchPattern, replacement)

正規表現を使用して、指定したテキスト パターンをすべて指定した置換文字列に置き換えます。

検索パターンは、JavaScript 正規表現オブジェクトではなく、文字列として渡されます。そのため、パターン内のバックスラッシュをエスケープする必要があります。

このメソッドは Google の RE2 正規表現ライブラリを使用します。このライブラリにより、サポートされている構文が制限されます。

指定された正規表現パターンは、現在の要素に含まれている各テキスト ブロックと個別に照合されます。

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

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

パラメータ

名前説明
searchPatternString検索する正規表現パターンを
replacementString置換として使用するテキストです。

リターン

Element - 現在の要素

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • 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 - 現在の要素。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • 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 - 現在の要素。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setBorderWidth(width)

枠線の太さをポイント単位で設定します。

パラメータ

名前説明
widthNumber枠線の幅(ポイント単位)

リターン

Table - 現在の要素

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setColumnWidth(columnIndex, width)

指定された列の幅をポイント単位で設定します。

パラメータ

名前説明
columnIndexInteger列インデックス
widthNumber枠線の幅(ポイント単位)

リターン

Table - 現在の要素

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setLinkUrl(url)

リンクの URL を設定します。

パラメータ

名前説明
urlStringリンク URL

リターン

Table - 現在の要素

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setTextAlignment(textAlignment)

テキストの配置を設定します。使用可能なアライメントのタイプは、DocumentApp.TextAlignment.NORMALDocumentApp.TextAlignment.SUBSCRIPTDocumentApp.TextAlignment.SUPERSCRIPT です。

// Make the entire first paragraph be superscript.
var text = DocumentApp.getActiveDocument().getBody().getParagraphs()[0].editAsText();
text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);

パラメータ

名前説明
textAlignmentTextAlignment適用するテキストの配置の種類

リターン

Table - 現在の要素

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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