How to create a filtered list in an Excel file in C#

This c# example allows to insert a list filter into a sheet of a Excel xls file. This filter allows to select only the rows where the selected cell content matches the criteria. The method needs the top left and bottom right cell coordinates to generate the list.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
/// <summary> /// This method creates a Excel filtered list. /// Only the cell content matching the filter criteria will be selected /// </summary> /// <param name="ws">Worksheet to use</param> /// <param name="excelList_firstCell">First cell of List (top left, eg A2)</param> /// <param name="excelList_lastCell">Last cell of List (bottom right, eg J22)</param> private void Excel_createFilteredList(Worksheet ws, string excelList_firstCell, string excelList_lastCell) { ws.get_Range(excelList_firstCell, excelList_lastCell).AutoFilter(1, System.Reflection.Missing.Value, XlAutoFilterOperator.xlAnd, System.Reflection.Missing.Value, true); ws.get_Range(excelList_firstCell, excelList_lastCell).Borders.LineStyle = XlLineStyle.xlContinuous; }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus