Class AutoFilter
Namespace: Aspose.Cells
Assembly: Aspose.Cells.dll (25.2.0)
表示指定工作表的自动筛选。
public class AutoFilter
继承
继承成员
object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
示例
//创建一个包含要打开的Excel文件的文件流
//实例化一个Workbook对象
Workbook workbook = new Workbook("template.xlsx");
//访问Excel文件中的第一个工作表
Worksheet worksheet = workbook.Worksheets[0];
//通过指定标题行的单元格范围创建AutoFilter
worksheet.AutoFilter.Range = "A1:B1";
//使用指定值过滤列
worksheet.AutoFilter.Filter(1, "Bananas");
//保存修改后的Excel文件。
workbook.Save("output.xls");
'创建一个包含要打开的Excel文件的文件流
'实例化一个Workbook对象
Dim workbook As Workbook = New Workbook("template.xlsx")
'访问Excel文件中的第一个工作表
Dim worksheet As Worksheet = workbook.Worksheets(0)
'通过指定标题行的单元格范围创建AutoFilter
worksheet.AutoFilter.Range = "A1:B1"
'使用指定值过滤列
Worksheet.AutoFilter.Filter(1, "Bananas")
'保存修改后的Excel文件
workbook.Save("output.xls")
属性
FilterColumns
获取过滤列的集合。
public FilterColumnCollection FilterColumns { get; }
属性值
Range
表示指定的AutoFilter应用的范围。
public string Range { get; set; }
属性值
ShowFilterButton
指示此列的AutoFilter按钮是否可见。
public bool ShowFilterButton { get; set; }
属性值
Sorter
获取数据排序器。
public DataSorter Sorter { get; }
属性值
方法
AddDateFilter(int, DateTimeGroupingType, int, int, int, int, int, int)
添加日期过滤器。
public void AddDateFilter(int fieldIndex, DateTimeGroupingType dateTimeGroupingType, int year, int month, int day, int hour, int minute, int second)
参数
fieldIndex
int
要基于其过滤器的字段的整数偏移量 (从列表的左侧开始;最左边的字段为字段0)。
dateTimeGroupingType
DateTimeGroupingType
分组类型
year
int
年份。
month
int
月份。
day
int
日期。
hour
int
小时。
minute
int
分钟。
second
int
秒。
备注
如果DateTimeGroupingType为Year,则只有参数year有效。 如果DateTimeGroupingType为Month,则只有参数year和month有效。
AddFillColorFilter(int, BackgroundType, CellsColor, CellsColor)
添加填充颜色过滤器。
public void AddFillColorFilter(int fieldIndex, BackgroundType pattern, CellsColor foregroundColor, CellsColor backgroundColor)
参数
fieldIndex
int
要基于其过滤器的字段的整数偏移量 (从列表的左侧开始;最左边的字段为字段0)。
pattern
BackgroundType
背景模式类型。
foregroundColor
CellsColor
前景颜色。
backgroundColor
CellsColor
背景颜色。
AddFilter(int, string)
为过滤列添加过滤器。
public void AddFilter(int fieldIndex, string criteria)
参数
fieldIndex
int
要基于其过滤器的字段的整数偏移量 (从列表的左侧开始;最左边的字段为字段0)。
criteria
string
指定的条件(字符串;例如,“101”)。 只能为null或此列中的单元格值之一。
备注
MS Excel 2007支持在过滤列中进行多重选择。
AddFontColorFilter(int, CellsColor)
添加字体颜色过滤器。
public void AddFontColorFilter(int fieldIndex, CellsColor color)
参数
fieldIndex
int
要基于其过滤器的字段的整数偏移量 (从列表的左侧开始;最左边的字段为字段0)。
color
CellsColor
Aspose.Cells.CellsColor对象。
AddIconFilter(int, IconSetType, int)
添加图标过滤器。
public void AddIconFilter(int fieldIndex, IconSetType iconSetType, int iconId)
参数
fieldIndex
int
要基于其过滤器的字段的整数偏移量 (从列表的左侧开始;最左边的字段为字段0)。
iconSetType
IconSetType
图标集类型。
iconId
int
图标id。
备注
仅支持添加图标过滤器。 不支持检查过滤器为图标过滤器时哪些行是可见的。
Custom(int, FilterOperatorType, object)
使用自定义条件过滤列表。
public void Custom(int fieldIndex, FilterOperatorType operatorType1, object criteria1)
参数
fieldIndex
int
要基于其过滤器的字段的整数偏移量 (从列表的左侧开始;最左边的字段为字段0)。
operatorType1
FilterOperatorType
过滤器操作符类型
criteria1
object
自定义条件
Custom(int, FilterOperatorType, object, bool, FilterOperatorType, object)
使用自定义条件过滤列表。
public void Custom(int fieldIndex, FilterOperatorType operatorType1, object criteria1, bool isAnd, FilterOperatorType operatorType2, object criteria2)
参数
fieldIndex
int
要基于其过滤器的字段的整数偏移量 (从列表的左侧开始;最左边的字段为字段0)。
operatorType1
FilterOperatorType
过滤器操作符类型
criteria1
object
自定义条件
isAnd
bool
operatorType2
FilterOperatorType
过滤器操作符类型
criteria2
object
自定义条件
DynamicFilter(int, DynamicFilterType)
添加动态过滤器。
public void DynamicFilter(int fieldIndex, DynamicFilterType dynamicFilterType)
参数
fieldIndex
int
要基于其过滤器的字段的整数偏移量 (从列表的左侧开始;最左边的字段为字段0)。
dynamicFilterType
DynamicFilterType
动态过滤器类型。
Filter(int, string)
使用指定条件过滤列表。
public void Filter(int fieldIndex, string criteria)
参数
fieldIndex
int
要基于其过滤器的字段的整数偏移量 (从列表的左侧开始;最左边的字段为字段0)。
criteria
string
指定的条件(字符串;例如,“101”)。
备注
Aspose.Cells将删除此字段上的所有其他过滤设置,如Ms Excel 97-2003。
FilterTop10(int, bool, bool, int)
过滤列表中的前10个项目
public void FilterTop10(int fieldIndex, bool isTop, bool isPercent, int itemCount)
参数
fieldIndex
int
要基于其过滤器的字段的整数偏移量 (从列表的左侧开始;最左边的字段为字段0)。
isTop
bool
指示从顶部还是底部过滤
isPercent
bool
指示项目是百分比还是计数
itemCount
int
项目计数
GetCellArea()
获取此AutoFilter适用的Aspose.Cells.CellArea。
public CellArea GetCellArea()
返回
此过滤器适用的区域
GetCellArea(bool)
获取指定AutoFilter适用的Aspose.Cells.CellArea。
public CellArea GetCellArea(bool refreshAppliedRange)
参数
refreshAppliedRange
bool
是否刷新应用范围。 对于自动过滤器的应用范围,当单元格数据更改时,最后一行可能会更改。 如果此标志为true,则范围的最后一行将根据当前单元格数据重新计算。
返回
此过滤器适用的区域
MatchBlanks(int)
匹配列表中的所有空白单元格。
public void MatchBlanks(int fieldIndex)
参数
fieldIndex
int
要基于其过滤器的字段的整数偏移量 (从列表的左侧开始;最左边的字段为字段0)。
MatchNonBlanks(int)
匹配列表中的所有非空单元格。
public void MatchNonBlanks(int fieldIndex)
参数
fieldIndex
int
要基于其过滤器的字段的整数偏移量 (从列表的左侧开始;最左边的字段为字段0)。
Refresh()
刷新自动过滤器以隐藏或显示行。
public int[] Refresh()
返回
int[]
返回所有隐藏行的索引。
Refresh(bool)
获取所有隐藏行的索引。
public int[] Refresh(bool hideRows)
参数
hideRows
bool
如果为true,则隐藏过滤的行。
返回
int[]
返回所有隐藏行的索引。
RemoveDateFilter(int, DateTimeGroupingType, int, int, int, int, int, int)
移除日期过滤器。
public void RemoveDateFilter(int fieldIndex, DateTimeGroupingType dateTimeGroupingType, int year, int month, int day, int hour, int minute, int second)
参数
fieldIndex
int
要基于其过滤器的字段的整数偏移量 (从列表的左侧开始;最左边的字段为字段0)。
dateTimeGroupingType
DateTimeGroupingType
分组类型
year
int
年份。
month
int
月份。
day
int
日期。
hour
int
小时。
minute
int
分钟。
second
int
秒。
备注
如果DateTimeGroupingType为Year,则只有参数year有效。 如果DateTimeGroupingType为Month,则只有参数year和month有效。
RemoveFilter(int, string)
移除过滤列的过滤器。
public void RemoveFilter(int fieldIndex, string criteria)
参数
fieldIndex
int
要基于其过滤器的字段的整数偏移量 (从列表的左侧开始;最左边的字段为字段0)。
criteria
string
指定的条件(字符串;例如,“101”)。 只能为null或此列中的单元格值之一。
RemoveFilter(int)
移除特定过滤器。
public void RemoveFilter(int fieldIndex)
参数
fieldIndex
int
特定过滤器索引
SetRange(int, int, int)
设置指定AutoFilter应用的范围。
public void SetRange(int row, int startColumn, int endColumn)
参数
row
int
行索引。
startColumn
int
起始列索引。
endColumn
int
结束列索引。
ShowAll()
取消隐藏所有行。
public void ShowAll()