Query for a range contained by Range.AutoFilter -
02-17-2010
, 01:46 PM
C# 3.0, Window XP Pro, Visual Studio 2008, Office 2007
I am able to generate a filter using the Range.AutoFilter method on a
ListObject table in Excel. However, elsewhere in the application, I want to
be able to get that filtered range into a Range object.
Any suggestions on how I can go about doing this?
Here is the method I use to filter based on a list of recordId's and a
boolean to either apply or not apply the filter.
void displayRelatedRecordsOnly(bool applyFilter, List<int> recsToShow)
{
object[] criteria = new object[recsToShow.Count];
List<object> oList = new List<object>();
int i = 0;
foreach (int recId in recsToShow)
{
criteria[i++] = recId.ToString();
}
Excel.XlAutoFilterOperator op =
Excel.XlAutoFilterOperator.xlFilterValues;
int idOrdinal = columnPositionByNames["ID"];
dataTable.Range.AutoFilter(idOrdinal,
applyFilter ? criteria : missing,
op, missing, true);
} |