Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EPPlus autofilter only working on last cell

Tags:

I would like each cell in the header to contain an autofilter. Below is the code I'm trying to use however the autofilter only gets set on the last cell specified.

For example, if I comment out the autofilter command for K1, the spreadsheet will be created with C1 being the only cell with an autofilter.

        //Headers         ws.Cells["A1"].Value = "ChannelCode";         ws.Cells["A1"].AutoFilter = true;         ws.Cells["B1"].Value = "DrmTerrDesc";         ws.Cells["B1"].AutoFilter = true;         ws.Cells["C1"].Value = "IndDistrnId";         ws.Cells["C1"].AutoFilter = true;         ws.Cells["D1"].Value = "StateCode";         ws.Cells["D1"].AutoFilter = true;         ws.Cells["E1"].Value = "ZipCode";         ws.Cells["E1"].AutoFilter = true;         ws.Cells["F1"].Value = "EndDate";         ws.Cells["F1"].AutoFilter = true;         ws.Cells["G1"].Value = "EffectiveDate";         ws.Cells["G1"].AutoFilter = true;         ws.Cells["H1"].Value = "LastUpdateId";         ws.Cells["H1"].AutoFilter = true;         ws.Cells["I1"].Value = "ErrorCodes";         ws.Cells["I1"].AutoFilter = true;         ws.Cells["J1"].Value = "Status";         ws.Cells["J1"].AutoFilter = true;         ws.Cells["K1"].Value = "Id";         ws.Cells["K1"].AutoFilter = true; 
like image 982
NealR Avatar asked Dec 30 '13 22:12

NealR


2 Answers

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

ws.Cells["A1:K1"].AutoFilter = true; 
like image 97
Vland Avatar answered Oct 18 '22 09:10

Vland


For all sheet data range

worksheet.Cells[worksheet.Dimension.Address].AutoFilter=true; 
like image 22
Ilya Klementiev Avatar answered Oct 18 '22 09:10

Ilya Klementiev