Excel.ShowAsCalculation enum

DataPivotField 的 ShowAs 计算函数。

注解

[ API 集:ExcelApi 1.8 ]

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/38-pivottable/pivottable-calculations.yaml

await Excel.run(async (context) => {
    const pivotTable = context.workbook.worksheets.getActiveWorksheet().pivotTables.getItem("Farm Sales");
    const farmDataHierarchy: Excel.DataPivotHierarchy = pivotTable.dataHierarchies.getItem("Sum of Crates Sold at Farm");        
    const wholesaleDataHierarchy: Excel.DataPivotHierarchy = pivotTable.dataHierarchies.getItem("Sum of Crates Sold Wholesale");

    farmDataHierarchy.load("showAs");
    wholesaleDataHierarchy.load("showAs");
    await context.sync();

    // Show the crates of each fruit type sold at the farm as a percentage of the column's total.
    let farmShowAs = farmDataHierarchy.showAs;
    farmShowAs.calculation = Excel.ShowAsCalculation.percentOfColumnTotal;
    farmShowAs.baseField = pivotTable.rowHierarchies.getItem("Type").fields.getItem("Type");
    farmDataHierarchy.showAs = farmShowAs;

    let wholesaleShowAs = wholesaleDataHierarchy.showAs;
    wholesaleShowAs.calculation = Excel.ShowAsCalculation.percentOfColumnTotal;
    wholesaleShowAs.baseField = pivotTable.rowHierarchies.getItem("Type").fields.getItem("Type");
    wholesaleDataHierarchy.showAs = wholesaleShowAs;
    await context.sync();
});

字段

differenceFrom = "DifferenceFrom"

与指定的基字段和基项的差异。

index = "Index"

按如下所示计算值:单元格中的 ( (值) x (总计) ) / ( (大行总计) x (大列总计) )

none = "None"

不应用任何计算。

percentDifferenceFrom = "PercentDifferenceFrom"

与指定的基字段和基项的差异。

percentOf = "PercentOf"

指定基字段和基项的百分比。

percentOfColumnTotal = "PercentOfColumnTotal"

列总数的百分比。

percentOfGrandTotal = "PercentOfGrandTotal"

占总计的百分比。

percentOfParentColumnTotal = "PercentOfParentColumnTotal"

指定基字段的列总数的百分比。

percentOfParentRowTotal = "PercentOfParentRowTotal"

指定基字段的行总数的百分比。

percentOfParentTotal = "PercentOfParentTotal"

指定基字段的总和的百分比。

percentOfRowTotal = "PercentOfRowTotal"

占行总数的百分比。

percentRunningTotal = "PercentRunningTotal"

指定基字段的总运行百分比。

rankAscending = "RankAscending"

指定基字段的升序排名。

rankDecending = "RankDecending"

指定基字段的降序排名。

runningTotal = "RunningTotal"

运行指定基字段的总计。

unknown = "Unknown"

计算未知或不受支持。