GetDynamicFilterParameters
(
Microsoft.Office.Interop.Excel.Workbook workbook,
String worksheetName,
String tableName
)
{
Debug.Assert(workbook != null);
Debug.Assert( !String.IsNullOrEmpty(worksheetName) );
Debug.Assert( !String.IsNullOrEmpty(tableName) );
#if false // For testing.
return ( GetRandomDynamicFilterParameters(tableName) );
#endif
LinkedList<DynamicFilterParameters> oDynamicFilterParameters =
new LinkedList<DynamicFilterParameters>();
// Get the specified table and loop through its columns.
ListObject oTable;
if (ExcelTableUtil.TryGetTable(workbook, worksheetName, tableName,
out oTable) )
{
Application oApplication = workbook.Application;
foreach (ListColumn oColumn in oTable.ListColumns)
{
if ( ColumnShouldBeExcluded(oColumn) )
{
continue;
}
ExcelColumnFormat eColumnFormat =
ExcelTableUtil.GetTableColumnFormat(oColumn);
switch (eColumnFormat)
{
case ExcelColumnFormat.Number:
case ExcelColumnFormat.Date:
case ExcelColumnFormat.Time:
case ExcelColumnFormat.DateAndTime:
// Get the range of values in the column.
Double dMinimumCellValue, dMaximumCellValue;
if ( TryGetNumericRange(worksheetName, oColumn,
out dMinimumCellValue, out dMaximumCellValue) )
{
if (eColumnFormat == ExcelColumnFormat.Number)
{
oDynamicFilterParameters.AddLast(
new NumericFilterParameters(oColumn.Name,
dMinimumCellValue, dMaximumCellValue,
ExcelTableUtil.GetTableColumnDecimalPlaces(
oColumn) )
);
}
else
{
oDynamicFilterParameters.AddLast(
new DateTimeFilterParameters(oColumn.Name,
dMinimumCellValue, dMaximumCellValue,
eColumnFormat) );
}
}
break;
case ExcelColumnFormat.Other:
// Skip the column.
break;
default:
Debug.Assert(false);
break;
}
}
}
return (oDynamicFilterParameters);
}