Filtering rows in a particular column is as easy as pie in EPPlus:
private ExcelWorksheet prodUsageWorksheet;
. . .
prodUsageWorksheet.Cells["A6:A6"].AutoFilter = true;
This allows me to filter the rows in column A:
I also need to filter certain columns out, such as the month columns (in the screenshot, Sep 15 and Oct 15, but are usually several more). For example, I want to generate the following programmatically with EPPlus:
Deselecting "Select All", selecting a subset of months, and then clicking the OK button makes the one[s] not selected collapse.
Looking at some legacy Excel Interop code, it would seem that there, it is done like this:
fld = ((PivotField) pvt.PivotFields("Month"));
fld.Orientation = XlPivotFieldOrientation.xlColumnField;
fld.NumberFormat = "MMM yy";
Specifically, the second block of code (with the orientation set to xlColumnField
) is the column that sports the sort/filter button that, when manipulated, conditionally shows/hides various columns.
Does it determine which columns are showable/hideable based on the number format? That is to say, if the value is "Sep 15" or "Oct 16"?
I don't know, but I can't see anything else in the code that is more specifically setting the limits of the column filtering.
At any rate, if this is how Excel Interop accomplishes it, what is the equivalent in EPPlus?
This has been asked in another posting. Also, this is not what EPPlus is intended for, as column filtering is more a 'Dynamic' end user functionality.
Take a look at this and see if it answers your question: