ExcelScript.TableColumn interface

代表表格中的一列。

注解

示例

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

  // Get the range of the table column named "Type".
  const typeColumn : ExcelScript.TableColumn = table.getColumn("Type");
  const range = typeColumn.getRange();

  // Do something with the range...
}

方法

delete()

从表中删除列。

getFilter()

检索应用于列的筛选器。

getHeaderRowRange()

获取与列的标头行相关的 range 对象。

getId()

返回标识表内的列的唯一键。

getIndex()

返回表的列集合内列的索引编号。 从零开始编制索引。

getName()

指定表列的名称。

getRange()

获取与整个列相关的 range 对象。

getRangeBetweenHeaderAndTotal()

获取与列的数据体相关的 range 对象。

getTotalRowRange()

获取与列的总计行相关的 range 对象。

setName(name)

指定表列的名称。

方法详细信息

delete()

从表中删除列。

delete(): void;

返回

void

示例

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

getFilter()

检索应用于列的筛选器。

getFilter(): Filter;

返回

示例

/**
 * This script adds a table filter to only show the top 10% of values 
 * belonging to a particular column.
 */
function main(workbook: ExcelScript.Workbook) {
    // Get the first table on the current worksheet.
    const table = workbook.getActiveWorksheet().getTables()[0];

    // Get the filter for the "PageViews" table column.
    const pageViewFilter = table.getColumnByName("PageViews").getFilter();

    // Apply a filter to only show the rows with the top 10% of values in this column.
    pageViewFilter.applyTopPercentFilter(10);
}

getHeaderRowRange()

获取与列的标头行相关的 range 对象。

getHeaderRowRange(): Range;

返回

getId()

返回标识表内的列的唯一键。

getId(): number;

返回

number

getIndex()

返回表的列集合内列的索引编号。 从零开始编制索引。

getIndex(): number;

返回

number

getName()

指定表列的名称。

getName(): string;

返回

string

getRange()

获取与整个列相关的 range 对象。

getRange(): Range;

返回

getRangeBetweenHeaderAndTotal()

获取与列的数据体相关的 range 对象。

getRangeBetweenHeaderAndTotal(): Range;

返回

示例

/**
 * 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}]]`
  );
}

getTotalRowRange()

获取与列的总计行相关的 range 对象。

getTotalRowRange(): Range;

返回

示例

/**
 * This script logs the value in the total row of a table column.
 */
function main(workbook: ExcelScript.Workbook) {
    // Get the table named "Cities".
    const table = workbook.getTable("Cities");

    // Get the total row from the "Population" column.
    const column = table.getColumn("Population");
    const totalRange = column.getTotalRowRange();

    // Log the total value.
    console.log(totalRange.getValue());
}

setName(name)

指定表列的名称。

setName(name: string): void;

参数

name

string

返回

void

示例

/**
 * This script renames a column in an existing table.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the "Employee" table.
  const employeeTable = workbook.getTable("Employee");

  // Rename a column from "EmplID" to "Employee ID".
  const idColumn = employeeTable.getColumnByName("EmplID");
  idColumn.setName("Employee ID");
}