ExcelScript.Table interface

Excel の表を表します。

注釈

/**
 * This script creates a table from the current sheet's used range.
 * It then adds a total row to the table with the SUM of the last column.
 */
function main(workbook: ExcelScript.Workbook) {
    // Get the used range of the current worksheet.
    const sheet = workbook.getActiveWorksheet();
    const range = sheet.getUsedRange();

    // Create a table that has headers from that range.
    const table = sheet.addTable(range, true);

    // Have the table display the SUM for the last column.
    table.setShowTotals(true);
    const lastColumn = table.getColumn(table.getColumns().length);
    lastColumn.getTotalRowRange().setFormula(`=SUBTOTAL(109,[${lastColumn.getName()}])`);
}

メソッド

addColumn(index, values, name)

テーブルに新しい列を追加します。

addRow(index, values)

テーブルに 1 行を追加します。

addRows(index, values)

テーブルに 1 つ以上の行を追加します。

clearFilters()

現在テーブルに適用されているすべてのフィルターをクリアします。

convertToRange()

テーブルを通常の範囲のセルに変換します。 すべてのデータが保持されます。

delete()

テーブルを削除します。

deleteRowsAt(index, count)

指定したインデックス位置にある指定した数の行を削除します。

getAutoFilter()

テーブルの AutoFilter オブジェクトを表します。

getColumn(key)

名前または ID によって、列オブジェクトを取得します。 列が存在しない場合、このメソッドは を返します undefined

getColumnById(key)

ID で列オブジェクトを取得します。 列が存在しない場合は、undefined が返されます。

getColumnByName(key)

Name で列オブジェクトを取得します。 列が存在しない場合は、undefined が返されます。

getColumns()

テーブルに含まれるすべての列のコレクションを表します。

getHeaderRowRange()

表のヘッダー行に関連付けられた範囲オブジェクトを取得します。

getHighlightFirstColumn()

最初の列に特別な書式が含まれているかどうかを指定します。

getHighlightLastColumn()

最後の列に特別な書式が含まれているかどうかを指定します。

getId()

指定されたブックのテーブルを一意に識別する値を返します。 識別子の値は、テーブルの名前が変更された場合も変わりません。

getLegacyId()

数値 ID を返します。

getName()

テーブルの名前。

getPredefinedTableStyle()

テーブル スタイルを表す定数値。 使用できる値は、"TableStyleLight1" から "TableStyleLight21"、"TableStyleMedium1" から "TableStyleMedium28"、"TableStyleDark1" から "TableStyleDark11" です。 ブックに存在するカスタムのユーザー定義スタイルも指定できます。

getRange()

テーブル全体に関連付けられた範囲オブジェクトを取得します。

getRangeBetweenHeaderAndTotal()

テーブルのデータ本体に関連付けられた範囲オブジェクトを取得します。

getRowCount()

表の行数を取得します。

getShowBandedColumns()

テーブルの読み取りを容易にするために、奇数列が偶数列とは異なる方法で強調表示されるバンド形式を列に表示するかどうかを指定します。

getShowBandedRows()

テーブルの読み取りを容易にするために、奇数行が偶数行とは異なる方法で強調表示されるバンド形式を行に表示するかどうかを指定します。

getShowFilterButton()

各列ヘッダーの上部にフィルター ボタンを表示するかどうかを指定します。 これは、テーブルにヘッダー行が含まれている場合のみ設定できます。

getShowHeaders()

ヘッダー行を表示するかどうかを指定します。 この値によって、ヘッダー行の表示または削除を設定できます。

getShowTotals()

合計行を表示するかどうかを指定します。 この値によって、集計行の表示または削除を設定できます。

getSort()

テーブル内の並べ替えを表します。

getTotalRowRange()

表の集計行に関連付けられた範囲オブジェクトを取得します。

getWorksheet()

現在のテーブルを含んでいるワークシート。

reapplyFilters()

現在テーブルにあるすべてのフィルターを再適用します。

resize(newRange)

テーブルのサイズを新しい範囲に変更します。 新しい範囲は元のテーブル範囲と重複する必要があり、ヘッダー (またはテーブルの先頭) は同じ行に存在する必要があります。

setHighlightFirstColumn(highlightFirstColumn)

最初の列に特別な書式が含まれているかどうかを指定します。

setHighlightLastColumn(highlightLastColumn)

最後の列に特別な書式が含まれているかどうかを指定します。

setName(name)

テーブルの名前。

setPredefinedTableStyle(predefinedTableStyle)

テーブル スタイルを表す定数値。 使用できる値は、"TableStyleLight1" から "TableStyleLight21"、"TableStyleMedium1" から "TableStyleMedium28"、"TableStyleDark1" から "TableStyleDark11" です。 ブックに存在するカスタムのユーザー定義スタイルも指定できます。

setShowBandedColumns(showBandedColumns)

テーブルの読み取りを容易にするために、奇数列が偶数列とは異なる方法で強調表示されるバンド形式を列に表示するかどうかを指定します。

setShowBandedRows(showBandedRows)

テーブルの読み取りを容易にするために、奇数行が偶数行とは異なる方法で強調表示されるバンド形式を行に表示するかどうかを指定します。

setShowFilterButton(showFilterButton)

各列ヘッダーの上部にフィルター ボタンを表示するかどうかを指定します。 これは、テーブルにヘッダー行が含まれている場合のみ設定できます。

setShowHeaders(showHeaders)

ヘッダー行を表示するかどうかを指定します。 この値によって、ヘッダー行の表示または削除を設定できます。

setShowTotals(showTotals)

合計行を表示するかどうかを指定します。 この値によって、集計行の表示または削除を設定できます。

メソッドの詳細

addColumn(index, values, name)

テーブルに新しい列を追加します。

addColumn(
            index?: number,
            values?: (boolean | string | number)[],
            name?: string
        ): TableColumn;

パラメーター

index

number

オプション。 新しい列の相対位置を指定します。 null または -1 の場合、最後に追加が行われます。 上位のインデックスを持つ列は横にシフトされます。 0 を起点とする番号になります。

values

(boolean | string | number)[]

オプション。 テーブル列の書式設定されていない値の 1 次元配列。

name

string

オプション。 新しい列の名前を指定します。 null の場合は既定の名前が使用されます。

戻り値

/**
 * This script adds a new column to a table.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the first table in the workbook.
  const table = workbook.getTables()[0];

  // Append an empty column to the table with the header "Total". 
  table.addColumn(-1, null, "Total");
}

addRow(index, values)

テーブルに 1 行を追加します。

addRow(index?: number, values?: (boolean | string | number)[]): void;

パラメーター

index

number

オプション。 新しい行の相対位置を指定します。 null または -1 の場合、最後に追加が行われます。 挿入した行の下のすべての行が下方向にシフトします。 0 を起点とする番号になります。

values

(boolean | string | number)[]

オプション。 テーブル行の書式設定されていない値の 1 次元配列。

戻り値

void

/**
 * This script adds a row to an existing table.
 */
function main(workbook: ExcelScript.Workbook) {
    // Get the first table in the current worksheet.
    const selectedSheet = workbook.getActiveWorksheet();
    const table = selectedSheet.getTables()[0];

    // Initialize the data to be added as a table row.
    // Note that length of the array must match the number of columns in the table.
    let rowData = ["Carrots", "Vegetable", 750];

    // Add a row to the end of the table.
    table.addRow(-1, rowData);
}

addRows(index, values)

テーブルに 1 つ以上の行を追加します。

addRows(index?: number, values?: (boolean | string | number)[][]): void;

パラメーター

index

number

オプション。 新しい行の相対位置を指定します。 null または -1 の場合、最後に追加が行われます。 挿入した行の下のすべての行が下方向にシフトします。 0 を起点とする番号になります。

values

(boolean | string | number)[][]

オプション。 テーブルの行の書式設定されていない値の 2 次元の配列。

戻り値

void

/**
 * This script adds multiple rows to an existing table.
 */
function main(workbook: ExcelScript.Workbook) {
    // Get the first table in the current worksheet.
    const selectedSheet = workbook.getActiveWorksheet();
    const table = selectedSheet.getTables()[0];

    // Initialize the data to be added as table rows.
    // Note that length of the array must match the number of columns in the table.
    let rowData = [["Apples", "Fruit", 5000],
                  ["Celery", "Vegetable", 600],
                  ["Onions", "Vegetable", 1500]];

    // Add the rows to the end of the table.
    table.addRows(-1, rowData);
}

clearFilters()

現在テーブルに適用されているすべてのフィルターをクリアします。

clearFilters(): void;

戻り値

void

convertToRange()

テーブルを通常の範囲のセルに変換します。 すべてのデータが保持されます。

convertToRange(): Range;

戻り値

/**
 * This script converts a table to a range and removes the formatting.
 */
function main(workbook: ExcelScript.Workbook) {
    // Get the first table in the current worksheet.
    const selectedSheet = workbook.getActiveWorksheet();
    const table = selectedSheet.getTables()[0];

    // Convert the table to a range.
    const formerTable = table.convertToRange();

    // Remove the formatting from the table
    formerTable.clear(ExcelScript.ClearApplyTo.formats);
}

delete()

テーブルを削除します。

delete(): void;

戻り値

void

/**
 * This script deletes a table. 
 * This removes all associated data and formatting.
 */
function main(workbook: ExcelScript.Workbook) {
    // Get the table named "Inventory".
    const table = workbook.getTable("Inventory");

    // Delete the table.
    table.delete();
}

deleteRowsAt(index, count)

指定したインデックス位置にある指定した数の行を削除します。

deleteRowsAt(index: number, count?: number): void;

パラメーター

index

number

削除する行のインデックス値。 注意: 行のインデックスは、削除に使用する値を決定した時点から移動している可能性があります。

count

number

削除する行数。 既定では、1 つの行が削除されます。 注: 1000 を超える行を同時に削除すると、Power Automate のタイムアウトが発生する可能性があります。

戻り値

void

getAutoFilter()

テーブルの AutoFilter オブジェクトを表します。

getAutoFilter(): AutoFilter;

戻り値

getColumn(key)

名前または ID によって、列オブジェクトを取得します。 列が存在しない場合、このメソッドは を返します undefined

getColumn(key: number | string): TableColumn | undefined;

パラメーター

key

number | string

列名または ID。

戻り値

/**
 * This script adjusts the indentation of a specific table column.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the first table in the current worksheet.
  const selectedSheet = workbook.getActiveWorksheet();
  const table = selectedSheet.getTables()[0];

  // Get the data range of the second column.
  const secondColumn = table.getColumn(2);
  const data = secondColumn.getRangeBetweenHeaderAndTotal();

  // Add an indentation of 1 character space to the data range.
  data.getFormat().adjustIndent(1);
}

getColumnById(key)

ID で列オブジェクトを取得します。 列が存在しない場合は、undefined が返されます。

getColumnById(key: number): TableColumn | undefined;

パラメーター

key

number

列 ID。

戻り値

getColumnByName(key)

Name で列オブジェクトを取得します。 列が存在しない場合は、undefined が返されます。

getColumnByName(key: string): TableColumn | undefined;

パラメーター

key

string

列名。

戻り値

/**
 * This script removes a specific column from a table.
 */
function main(workbook: ExcelScript.Workbook) {
    // Get the table named "Inventory".
    const table = workbook.getTable("Inventory");

    // If it exists, remove the column named "Category".
    let categoryColumn = table.getColumnByName("Category");
    if (categoryColumn) {
        categoryColumn.delete();
    }
}

getColumns()

テーブルに含まれるすべての列のコレクションを表します。

getColumns(): TableColumn[];

戻り値

/**
 * This script adds a new column to a table.
 * It then sets the formulas in the new column to be the product
 * of the values in the two preceding columns.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the first table in the workbook.
  const table = workbook.getTables()[0];

  // Append an empty column to the table with the header "Total". 
  const totalColumn = table.addColumn(-1, null, "Total");

  // Get the names of the two preceding columns.
  const productColumnName1 = table.getColumns()[totalColumn.getIndex() - 1].getName();
  const productColumnName2 = table.getColumns()[totalColumn.getIndex() - 2].getName();
  
  // Set the formulas in the "Total" column to be the product of the two preceding columns.
  totalColumn.getRangeBetweenHeaderAndTotal().setFormula(
    `=[@[${productColumnName1}]]*[@[${productColumnName2}]]`
  );
}

getHeaderRowRange()

表のヘッダー行に関連付けられた範囲オブジェクトを取得します。

getHeaderRowRange(): Range;

戻り値

/**
 * This script centers the text in a table's header row cells.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the first table on the current worksheet.
  const currentSheet = workbook.getActiveWorksheet();
  const table = currentSheet.getTables()[0];

  // Get the header range.
  const headerRange = table.getHeaderRowRange();

  // Set the horizontal text alignment to `center`.
  headerRange.getFormat().setHorizontalAlignment(ExcelScript.HorizontalAlignment.center);
}

getHighlightFirstColumn()

最初の列に特別な書式が含まれているかどうかを指定します。

getHighlightFirstColumn(): boolean;

戻り値

boolean

getHighlightLastColumn()

最後の列に特別な書式が含まれているかどうかを指定します。

getHighlightLastColumn(): boolean;

戻り値

boolean

getId()

指定されたブックのテーブルを一意に識別する値を返します。 識別子の値は、テーブルの名前が変更された場合も変わりません。

getId(): string;

戻り値

string

getLegacyId()

数値 ID を返します。

getLegacyId(): string;

戻り値

string

getName()

テーブルの名前。

getName(): string;

戻り値

string

getPredefinedTableStyle()

テーブル スタイルを表す定数値。 使用できる値は、"TableStyleLight1" から "TableStyleLight21"、"TableStyleMedium1" から "TableStyleMedium28"、"TableStyleDark1" から "TableStyleDark11" です。 ブックに存在するカスタムのユーザー定義スタイルも指定できます。

getPredefinedTableStyle(): string;

戻り値

string

getRange()

テーブル全体に関連付けられた範囲オブジェクトを取得します。

getRange(): Range;

戻り値

/**
 * This script removes any extra formatting that's been applied to a table. 
 * This leaves only the base table style effects.
 * Any formatting outside of the table will be left as is.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the first table on the current worksheet.
  let worksheet = workbook.getActiveWorksheet();
  let table = worksheet.getTables()[0];

  // Get the range used by the table.
  let range = table.getRange();

  // Clear all the formatting that is not applied by the table and the table style.
  range.clear(ExcelScript.ClearApplyTo.formats);
}

getRangeBetweenHeaderAndTotal()

テーブルのデータ本体に関連付けられた範囲オブジェクトを取得します。

getRangeBetweenHeaderAndTotal(): Range;

戻り値

getRowCount()

表の行数を取得します。

getRowCount(): number;

戻り値

number

getShowBandedColumns()

テーブルの読み取りを容易にするために、奇数列が偶数列とは異なる方法で強調表示されるバンド形式を列に表示するかどうかを指定します。

getShowBandedColumns(): boolean;

戻り値

boolean

getShowBandedRows()

テーブルの読み取りを容易にするために、奇数行が偶数行とは異なる方法で強調表示されるバンド形式を行に表示するかどうかを指定します。

getShowBandedRows(): boolean;

戻り値

boolean

getShowFilterButton()

各列ヘッダーの上部にフィルター ボタンを表示するかどうかを指定します。 これは、テーブルにヘッダー行が含まれている場合のみ設定できます。

getShowFilterButton(): boolean;

戻り値

boolean

getShowHeaders()

ヘッダー行を表示するかどうかを指定します。 この値によって、ヘッダー行の表示または削除を設定できます。

getShowHeaders(): boolean;

戻り値

boolean

getShowTotals()

合計行を表示するかどうかを指定します。 この値によって、集計行の表示または削除を設定できます。

getShowTotals(): boolean;

戻り値

boolean

getSort()

テーブル内の並べ替えを表します。

getSort(): TableSort;

戻り値

getTotalRowRange()

表の集計行に関連付けられた範囲オブジェクトを取得します。

getTotalRowRange(): Range;

戻り値

getWorksheet()

現在のテーブルを含んでいるワークシート。

getWorksheet(): Worksheet;

戻り値

reapplyFilters()

現在テーブルにあるすべてのフィルターを再適用します。

reapplyFilters(): void;

戻り値

void

/**
 * This script reapplies the filters on every table in the workbook.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get all the tables.
  const tables = workbook.getTables();

  // Iterate over every table.
  tables.forEach((table) => {
    // Reapply the filters to account for new table entries.
    table.reapplyFilters();
  });
}

resize(newRange)

テーブルのサイズを新しい範囲に変更します。 新しい範囲は元のテーブル範囲と重複する必要があり、ヘッダー (またはテーブルの先頭) は同じ行に存在する必要があります。

resize(newRange: Range | string): void;

パラメーター

newRange

ExcelScript.Range | string

テーブルの新しいサイズを決定するために使用される範囲オブジェクトまたは範囲アドレス。

戻り値

void

setHighlightFirstColumn(highlightFirstColumn)

最初の列に特別な書式が含まれているかどうかを指定します。

setHighlightFirstColumn(highlightFirstColumn: boolean): void;

パラメーター

highlightFirstColumn

boolean

戻り値

void

setHighlightLastColumn(highlightLastColumn)

最後の列に特別な書式が含まれているかどうかを指定します。

setHighlightLastColumn(highlightLastColumn: boolean): void;

パラメーター

highlightLastColumn

boolean

戻り値

void

setName(name)

テーブルの名前。

setName(name: string): void;

パラメーター

name

string

戻り値

void

setPredefinedTableStyle(predefinedTableStyle)

テーブル スタイルを表す定数値。 使用できる値は、"TableStyleLight1" から "TableStyleLight21"、"TableStyleMedium1" から "TableStyleMedium28"、"TableStyleDark1" から "TableStyleDark11" です。 ブックに存在するカスタムのユーザー定義スタイルも指定できます。

setPredefinedTableStyle(predefinedTableStyle: string): void;

パラメーター

predefinedTableStyle

string

戻り値

void

setShowBandedColumns(showBandedColumns)

テーブルの読み取りを容易にするために、奇数列が偶数列とは異なる方法で強調表示されるバンド形式を列に表示するかどうかを指定します。

setShowBandedColumns(showBandedColumns: boolean): void;

パラメーター

showBandedColumns

boolean

戻り値

void

setShowBandedRows(showBandedRows)

テーブルの読み取りを容易にするために、奇数行が偶数行とは異なる方法で強調表示されるバンド形式を行に表示するかどうかを指定します。

setShowBandedRows(showBandedRows: boolean): void;

パラメーター

showBandedRows

boolean

戻り値

void

setShowFilterButton(showFilterButton)

各列ヘッダーの上部にフィルター ボタンを表示するかどうかを指定します。 これは、テーブルにヘッダー行が含まれている場合のみ設定できます。

setShowFilterButton(showFilterButton: boolean): void;

パラメーター

showFilterButton

boolean

戻り値

void

setShowHeaders(showHeaders)

ヘッダー行を表示するかどうかを指定します。 この値によって、ヘッダー行の表示または削除を設定できます。

setShowHeaders(showHeaders: boolean): void;

パラメーター

showHeaders

boolean

戻り値

void

/**
 * This script makes a table's headers not visible in the grid.
 */
function main(workbook: ExcelScript.Workbook) {
    // Get the table named "CoverageTable".
    const coverageTable = workbook.getTable("CoverageTable");

    // Make the header row not visible.
    coverageTable.setShowHeaders(false);
}

setShowTotals(showTotals)

合計行を表示するかどうかを指定します。 この値によって、集計行の表示または削除を設定できます。

setShowTotals(showTotals: boolean): void;

パラメーター

showTotals

boolean

戻り値

void

/**
 * This script adds the Total Row to an existing table.
 */
function main(workbook: ExcelScript.Workbook) {
    // Get the first table in the current worksheet.
    const selectedSheet = workbook.getActiveWorksheet();
    const table = selectedSheet.getTables()[0];

    // Set the Total Row to show.
    table.setShowTotals(true);
}