在epplus的数据透视表中隐藏小计 [英] Hiding subtotals in pivot table in epplus

查看:193
本文介绍了在epplus的数据透视表中隐藏小计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用EPPLUS生成我的数据透视表(请参阅此SO帖子).我有以下代码

I'm using EPPLUS to generate my pivot table (see this SO post). I have the following code

//group by fields
foreach (string row in _GroupByColumns)
{
    ExcelPivotTableField field = pivotTable.Fields[row];

    //field formating
    field.Sort = eSortType.Ascending;
    field.Outline = false;
    field.Compact = false;
    field.ShowAll = false;
    field.SubtotalTop = false; //doesn't work, subtotals still there when excel is opened

    //doesn't work, will result in "unreadable content" error when Excel is opened
    //field.SubTotalFunctions = eSubTotalFunctions.None;

    //add it to the pivot
    pivotTable.RowFields.Add(field);
}

_GroupByColumnsList<string>,其中包含我的按列分组.

_GroupByColumns is a List<string> that contains my group by columns.

我认为field.SubtotalTop = false;将隐藏小计.没有.当我打开Excel时,field.SubTotalFunctions = eSubTotalFunctions.None;会导致无效数据"错误.我还能尝试什么?

I thought field.SubtotalTop = false; would hide subtotals. It doesn't. field.SubTotalFunctions = eSubTotalFunctions.None; results in "invalid data" error when I open my Excel. What else can I try?

推荐答案

我知道这是一个老问题,但是我添加了这个答案,以防万一有人在这里使用Google.

I know this is an old question, but I'm adding this answer in case anybody Googles here.

在将字段添加到RowFields集合后,需要设置SubTotalFunctions属性 .这是因为将其添加到集合中会更改SubTotalFunctions对其进行调整的XML节点.这将起作用...

You need to set the SubTotalFunctions property after adding the field to the RowFields collection. This is because adding it to the collection changes the XML node that SubTotalFunctions makes adjustments to. This will work...

ExcelPivotTableField field = pivotTable.Fields[row];

pivotTable.RowFields.Add(field);//<-- ADD IT FIRST

//field formating
field.Sort = eSortType.Ascending;
field.Outline = false;
field.Compact = false;
field.ShowAll = false;
field.SubtotalTop = false;
field.SubTotalFunctions = eSubTotalFunctions.None;//<-- THIS WILL WORK NOW

这篇关于在epplus的数据透视表中隐藏小计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆