问题描述
我正在使用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);
}
_GroupByColumns
是List<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的数据透视表中隐藏小计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!