This project has moved. For the latest updates, please go here.

Filter Values

RegularAutoFilter1.jpg
->
RegularAutoFilter2.jpg
->
RegularAutoFilter3.jpg

            var wb = new XLWorkbook();
            var ws = wb.Worksheets.Add("AutoFilter");

            // Add a bunch of strings to filter
            ws.Cell("A1").SetValue("Numbers")
                         .CellBelow().SetValue(2)
                         .CellBelow().SetValue(3)
                         .CellBelow().SetValue(3)
                         .CellBelow().SetValue(5)
                         .CellBelow().SetValue(1)
                         .CellBelow().SetValue(4);

            // Add filters
            ws.RangeUsed().SetAutoFilter().Column(1).AddFilter(3)
                                                                       .AddFilter(1)
                                                                       .AddFilter(5);

            // Sort the filtered list
            ws.AutoFilter.Sort(1);

            wb.SaveAs("AutoFilter.xlsx");

Last edited Nov 8, 2011 at 5:20 AM by MDeLeon, version 4