EPPlus自动filter只能在最后一个单元上工作

我希望标题中的每个单元格都包含一个自动filter。 下面是我试图使用的代码,但是autofilter只能在指定的最后一个单元格上设置。

例如,如果我注释掉K1autofilter命令,电子表格将被创build, C1是唯一一个带有自动filter的单元。

  //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; 

EPPlus.AutoFilter是一个小车…我build议使用这样的范围:

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

对于所有图纸数据范围

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

这个代码应该有帮助。 我试过并testing过它。

 ws.AutoFilterAddress = new ExcelAddressBase(ws.Dimension.Address);