3

I'm creating an Excel file using the EPPlus library and C#.

In this Excel file there is a sheet with pivot table to which I'd like to add a filter field like in this manually created Excel sheet (Country):

Excel pivot table filter field

How can I do this using EPPlus?

splattne
  • 102,760
  • 52
  • 202
  • 249

1 Answers1

4

I did not see your code, but you can do something like this.

var ws = excelPackage.Workbook.Worksheets["index of your worksheet"];
var pivotTable = ws.PivotTables[0]; //assuming that you only have 1
var pivotField = pivotTable.Fields["Country"];
pivotTable.PageFields.Add(pivotField); // should add field into desired place

Hope it´s a little bit helpful. Don´t forget to save your excel file at the end.

LoWesT
  • 129
  • 9