ExcelScript.ShowAsRule interface
注解
示例
/**
* The script changes the display for "Crates Sold at Farm".
* The field shows each value's difference
* from the value of the "Lemon" in the same row.
* If the row has no value for "Lemon", the field shows "#N/A".
*/
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");
// Get the row hierarchy "Type".
const typeField = farmPivot.getRowHierarchy("Type").getFields()[0];
// Change the data hierarchy to show each value as the difference
// from the value of the "Lemon" in that row.
const rule: ExcelScript.ShowAsRule = {
calculation: ExcelScript.ShowAsCalculation.differenceFrom,
baseField: typeField,
baseItem: typeField.getPivotItem("Lemon")
}
farmSales.setShowAs(rule);
// Set the name of the field to match the new behavior.
farmSales.setName("Difference from Lemons of Crates Sold at Farm");
}
属性
base |
计算依据的 |
base |
要基于计算的 |
calculation |
|
属性详细信息
baseField
计算依据的 ShowAs
透视字段(如果适用,根据 ShowAsCalculation
类型),否则 null
为 。
baseField?: PivotField;
属性值
baseItem
要基于计算的 ShowAs
项(如果适用,根据 ShowAsCalculation
类型),否则 null
为 。
baseItem?: PivotItem;
属性值
calculation
ShowAs
用于透视字段的计算。 有关详细信息,请参阅 ExcelScript.ShowAsCalculation
。
calculation: ShowAsCalculation;