簡體   English   中英

隱藏在epplus中的數據透視表中的小計

[英]Hiding subtotals in pivot table in epplus

我正在使用EPPLUS生成我的數據透視表( 請參閱此SO帖子 )。 我有以下代碼

//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> ,它按列包含我的組。

我以為field.SubtotalTop = false; 會隱藏小計。 它沒有。 field.SubTotalFunctions = eSubTotalFunctions.None; 打開Excel時導致“無效數據”錯誤。 我還能嘗試什么?

我知道這是一個老問題,但我添加了這個答案,以防任何人谷歌在這里。

將字段添加到RowFields集合后,需要設置SubTotalFunctions屬性。 這是因為將其添加到集合會更改SubTotalFunctions進行調整的XML節點。 這將有效......

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM