Workbook workbook = new Workbook(); workbook.LoadFromFile("test.xlsx"); Worksheet sheet = workbook.Worksheets[0]; //创建过滤器 sheet.ListObjects.Create("Table", sheet.Range[1, 1, sheet.LastRow, sheet.LastColumn]); sheet.ListObjects[0].BuiltInTableStyle = TableBuiltInStyles.TableStyleLight9; workbook.SaveToFile("Filter.xlsx", ExcelVersion.Version2010);
当然,有时候也需要取消过滤器,需要过滤器只需要一个下面一个清空操作即可:
sheet.AutoFilters.Clear();