ExcelScript.DataPivotHierarchy interface
表示 Excel DataPivotHierarchy。
注解
示例
/**
* This sample sorts the rows of a PivotTable.
*/
function main(workbook: ExcelScript.Workbook) {
// Get an existing PivotTable.
const pivotTable = workbook.getPivotTable("Farm Sales");
// Get the data hierarchy to use as the basis of the sort.
const valueFieldToSortOn: ExcelScript.DataPivotHierarchy = pivotTable.getDataHierarchy("Sum of Crates Sold Wholesale");
// Get the row to sort.
const rowToSort: ExcelScript.RowColumnPivotHierarchy = pivotTable.getRowHierarchy("Farm");
// Sort the "Farm" row's only field by the values in "Sum of Crates Sold Wholesale".
rowToSort.getFields()[0].sortByValues(ExcelScript.SortBy.descending, valueFieldToSortOn);
}
方法
get |
返回与 DataPivotHierarchy 相关联的 PivotFields。 |
get |
DataPivotHierarchy 的 ID。 |
get |
DataPivotHierarchy 的名称。 |
get |
DataPivotHierarchy 的数字格式。 |
get |
DataPivotHierarchy 的位置。 |
get |
指定是否应将数据显示为特定的摘要计算。 |
get |
指定是否显示 DataPivotHierarchy 的所有项。 |
set |
DataPivotHierarchy 的名称。 |
set |
DataPivotHierarchy 的数字格式。 |
set |
DataPivotHierarchy 的位置。 |
set |
指定是否应将数据显示为特定的摘要计算。 |
set |
指定是否显示 DataPivotHierarchy 的所有项。 |
set |
将 DataPivotHierarchy 重置回其默认值。 |
方法详细信息
getField()
getId()
DataPivotHierarchy 的 ID。
getId(): string;
返回
string
getName()
DataPivotHierarchy 的名称。
getName(): string;
返回
string
getNumberFormat()
DataPivotHierarchy 的数字格式。
getNumberFormat(): string;
返回
string
getPosition()
DataPivotHierarchy 的位置。
getPosition(): number;
返回
number
getShowAs()
getSummarizeBy()
指定是否显示 DataPivotHierarchy 的所有项。
getSummarizeBy(): AggregationFunction;
返回
setName(name)
DataPivotHierarchy 的名称。
setName(name: string): void;
参数
- name
-
string
返回
void
setNumberFormat(numberFormat)
DataPivotHierarchy 的数字格式。
setNumberFormat(numberFormat: string): void;
参数
- numberFormat
-
string
返回
void
setPosition(position)
DataPivotHierarchy 的位置。
setPosition(position: number): void;
参数
- position
-
number
返回
void
setShowAs(showAs)
指定是否应将数据显示为特定的摘要计算。
setShowAs(showAs: ShowAsRule): void;
参数
- showAs
- ExcelScript.ShowAsRule
返回
void
示例
/**
* The script changes the display for "Crates Sold at Farm".
* It shows the percentage of the grand total,
* instead of the default sum.
*/
function main(workbook: ExcelScript.Workbook) {
// Get the PivotTable named "Farm Pivot".
const farmPivot = workbook.getPivotTable("Farm Pivot");
// Get the data hierarchy "Sum of Crates Sold at Farm".
const farmSales = farmPivot.getDataHierarchy("Sum of Crates Sold at Farm");
// Show the data as a percentage of the grand total.
farmSales.setShowAs({
calculation: ExcelScript.ShowAsCalculation.percentOfGrandTotal
});
}
setSummarizeBy(summarizeBy)
指定是否显示 DataPivotHierarchy 的所有项。
setSummarizeBy(summarizeBy: AggregationFunction): void;
参数
- summarizeBy
- ExcelScript.AggregationFunction
返回
void
示例
/**
* This script changes how the data in a PivotTable is aggregated.
*/
function main(workbook: ExcelScript.Workbook) {
// Get the first PivotTable in the workbook.
const pivotTable = workbook.getPivotTables()[0];
// Set the first data hierarchy to summarize with an average value, instead of a sum.
const dataHierarchy = pivotTable.getDataHierarchies()[0];
dataHierarchy.setSummarizeBy(ExcelScript.AggregationFunction.average);
}
setToDefault()
将 DataPivotHierarchy 重置回其默认值。
setToDefault(): void;
返回
void