EPPlus autofilter only working on last cell

Solution 1:

EPPlus .AutoFilter is a little buggy... I suggest doing it using a range like this:

ws.Cells["A1:K1"].AutoFilter = true;

Solution 2:

For all sheet data range

worksheet.Cells[worksheet.Dimension.Address].AutoFilter=true;

Solution 3:

If you have a dynamic set of columns, or they are defined in an array or list:

string[] columns = new string[] { "Name", "City", "Street" };

worksheet.Cells[1, 1, 1, columns.Length].AutoFilter = true;

The overload used is as follows:

public ExcelRange this[int FromRow, int FromCol, int ToRow, int ToCol] { get; }

I personally prefer this instead of converting an integer (columns.Length) to an Excel range with characters (for ex. "A1:C1").