Applying multiple filters in ClosedXML (SetAutoFilter)

好久不见. 提交于 2021-01-29 03:44:16

问题


I am applying filters for multiple columns via ClosedXML; however, only the last one is applied. Those filters work when they are alone. How can I apply all of them? I found similar question here ClosedXML Excel filter rows by values in multiple columns

But there is no correct answer.

Here is the code:

var wb = new XLWorkbook(loc1);
var ws2 = wb.AddWorksheet("Итоги");
var ws1 =  wb.Worksheet(1);
var rowCount = ws1.RowsUsed().Count();
ws1.Range(ws1.Cell(3,1), ws1.LastCellUsed()).SetAutoFilter().Column(48).EqualTo("1");
ws1.Range(ws1.Cell(3,1), ws1.LastCellUsed()).SetAutoFilter().Column(8).NotContains("CLS");
ws1.Range(ws1.Cell(3,1), ws1.LastCellUsed()).SetAutoFilter().Column(2).BeginsWith("I");
wb.SaveAs(loc1);

Here, only filter for Column 2 is applied, but I want all filters being applied. Is there a way to do so? Thank you for your answers.


回答1:


It is not a direct solution, but you can apply Multiple Excel formulas using IF(OR(condition1, condition2,...),0,1) and then use only filter to get 1 or 0



来源:https://stackoverflow.com/questions/58095798/applying-multiple-filters-in-closedxml-setautofilter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!