Windows Phone Developers

Friday, July 30, 2010

C#/VB.NET Excel Autofilter - Specify Multiple Criteria using Array

C#/VB.NET Excel Autofilter - Only Last Value is Displayed

Here is a simple example of Filtering ListObjects using Excel AutoFilter function. This example uses the following spreadsheet



The following C# code will filter 'Apple' and 'Orange' using an Array


private void ExcelFilterExample() { String[] FilterList = {"Apple","Orange"}; Excel.Workbook oWB = Globals.ThisAddIn.Application.Workbooks.Open(@"C:\Users\comp\Documents\FreshFruitsnVegetables.xls"); Excel.Worksheet oWS = oWB.Worksheets[1]; oWS.ListObjects.AddEx (Excel.XlListObjectSourceType.xlSrcRange, oWS.UsedRange, System.Type.Missing ,Excel.XlYesNoGuess.xlYes).Name = "FruitList"; oWS.ListObjects["FruitList"].Range.AutoFilter(2, FilterList, Excel.XlAutoFilterOperator.xlFilterValues ); }
Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment

kbAlertz.com :: Visual Studio 2005

kbAlertz.com :: Visual Studio 2008

kbAlertz.com :: Visual Basic 2005