高级过滤器优于c# [英] advanced filter excel with c#
本文介绍了高级过滤器优于c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在excel表中做一个过滤器,我想知道是否可以做这样的过滤器
I need to do a filter in a excel sheet, I would like to know if is possible do a filter like this
List<string> listFilter = new List<string>();
listFilter.Add("3");
listFilter.Add("4");
object _missing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Excel.Range oRng1 = xlWorkSheet.Range["A1", "A1048576"];
oRng1.AutoFilter(1, listFilter, Microsoft.Office.Interop.Excel.XlAutoFilterOperator.xlAnd, _missing, true);
oRng1.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
我知道这段代码不起作用,但我想在筛选器中做一个dinamic列表参数。
有人可以告诉我我该怎么做?
I know that this code doesn't work but I would like to do a dinamic list in the filter parameter. Could someone tell me how can I do this?
推荐答案
我不知道传递列表,但你可以传递数组:
I'm not sure about passing lists, but you can definitely pass arrays:
string[] listfilter = new string[] { "2", "3", "4" };
xlWorksheet.get_Range("A1", "B50").AutoFilter(1, listfilter, Excel.XlAutoFilterOperator.xlFilterValues,
Missing.Value, true);
您可以找到 XlAutoFilterOperator的不同成员
此处。
尝试找到工作表中最后使用的行,而不是为整个列设置过滤器,这可能会减慢一些问题:
It might also be an idea to try to find the last-used row in the sheet rather than setting the filter for the entire column as that might slow things down a little:
int lastRow = xlWorksheet.Range["A:A"].Find("*", Missing.Value, Missing.Value, Missing.Value,
Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlPrevious, false, Missing.Value,
Missing.Value).Row;
这篇关于高级过滤器优于c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文