我希望标题中的每个单元格都包含一个自动过滤器.下面是我试图使用的代码,但是autofilter
只在指定的最后一个单元格上设置了.
例如,如果我注释掉该autofilter
命令K1
,则将创建电子表格,该电子表格是C1
唯一具有自动过滤器的单元格.
//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;
Vland.. 29
EPPlus .AutoFilter
是一个小小的车...我建议使用这样的范围:
ws.Cells["A1:K1"].AutoFilter = true;
Ilya Klement.. 17
适用于所有表单数据范围
worksheet.Cells[worksheet.Dimension.Address].AutoFilter=true;
Brian.. 5
如果您具有一组动态列,或者它们在数组或列表中定义:
string[] columns = new string[] { "Name", "City", "Street" }; worksheet.Cells[1, 1, 1, columns.Length].AutoFilter = true;
使用的重载如下:
public ExcelRange this[int FromRow, int FromCol, int ToRow, int ToCol] { get; }
我个人更喜欢此方法,而不是将整数(columns.Length)转换为带有字符的Excel范围(例如“ A1:C1”)。
适用于所有表单数据范围
worksheet.Cells[worksheet.Dimension.Address].AutoFilter=true;
EPPlus .AutoFilter
是一个小小的车...我建议使用这样的范围:
ws.Cells["A1:K1"].AutoFilter = true;
如果您具有一组动态列,或者它们在数组或列表中定义:
string[] columns = new string[] { "Name", "City", "Street" }; worksheet.Cells[1, 1, 1, columns.Length].AutoFilter = true;
使用的重载如下:
public ExcelRange this[int FromRow, int FromCol, int ToRow, int ToCol] { get; }
我个人更喜欢此方法,而不是将整数(columns.Length)转换为带有字符的Excel范围(例如“ A1:C1”)。