【问题标题】:Set PivotTable field calculation as DifferenceFrom next将数据透视表字段计算设置为 DifferenceFrom next
【发布时间】:2019-07-05 10:56:21
【问题描述】:

我尝试在使用 office.interop 创建的数据透视表中设置字段的计算

我需要设置 DifferenceFromNext,但在枚举中我发现只有 DifferenceFrom

var field = ((Microsoft.Office.Interop.Excel.PivotField)pvt.PivotFields((item as PropertyAggregateDescription).PropertyName));
field.Orientation = Microsoft.Office.Interop.Excel.XlPivotFieldOrientation.xlDataField;
field.Function = Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum;

field.Calculation = Microsoft.Office.Interop.Excel.XlPivotFieldCalculation.xlDifferenceFrom;

问题是它在错误的字段上计算

【问题讨论】:

  • 我无法通过 c# 和 microsoft.office.interop.excel\15.0.4795.1000\ 访问 PivotFields

标签: c# pivot-table office-interop excel-interop


【解决方案1】:

解决了设置基础项目,一定要在计算前设置基础项目,而不是触发异常

 field.Calculation = Microsoft.Office.Interop.Excel.XlPivotFieldCalculation.xlDifferenceFrom;
 field.BaseItem = "(next)";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-27
    • 1970-01-01
    • 1970-01-01
    • 2016-10-13
    相关资源
    最近更新 更多