AutoFilter

Inheritance: java.lang.Object

public class AutoFilter

Represents autofiltering for the specified worksheet.

Example

         //Creating a file stream containing the Excel file to be opened
         //Instantiating a Workbook object
         Workbook workbook = new Workbook("template.xlsx");
         //Accessing the first worksheet in the Excel file
         Worksheet worksheet = workbook.getWorksheets().get(0);
         //Creating AutoFilter by giving the cells range of the heading row
         worksheet.getAutoFilter().setRange("A1:B1");
         //Filtering columns with specified values
         worksheet.getAutoFilter().filter(1, "Bananas");
         //Saving the modified Excel file.
         workbook.save("output.xls");

Methods

MethodDescription
addDateFilter(int fieldIndex, int dateTimeGroupingType, int year, int month, int day, int hour, int minute, int second)Adds a date filter.
addFillColorFilter(int fieldIndex, int pattern, CellsColor foregroundColor, CellsColor backgroundColor)Adds a fill color filter.
addFilter(int fieldIndex, String criteria)Adds a filter for a filter column.
addFontColorFilter(int fieldIndex, CellsColor color)Adds a font color filter.
addIconFilter(int fieldIndex, int iconSetType, int iconId)Adds an icon filter.
custom(int fieldIndex, int operatorType1, Object criteria1)Filters a list with a custom criteria.
custom(int fieldIndex, int operatorType1, Object criteria1, boolean isAnd, int operatorType2, Object criteria2)Filters a list with custom criteria.
dynamicFilter(int fieldIndex, int dynamicFilterType)Adds a dynamic filter.
equals(Object arg0)
filter(int fieldIndex, String criteria)Filters a list with specified criteria.
filterTop10(int fieldIndex, boolean isTop, boolean isPercent, int itemCount)Filter the top 10 item in the list
getCellArea()Gets the CellArea where the specified AutoFilter applies to.
getClass()
getFilterColumns()Gets the collection of the filter columns.
getRange()Represents the range to which the specified AutoFilter applies.
getShowFilterButton()Indicates whether the AutoFilter button for this column is visible.
getSorter()Gets the data sorter.
hashCode()
matchBlanks(int fieldIndex)Match all blank cell in the list.
matchNonBlanks(int fieldIndex)Match all not blank cell in the list.
notify()
notifyAll()
refresh()Refresh auto filters to hide or unhide the rows.
refresh(boolean hideRows)Gets all hidden rows’ indexes.
removeDateFilter(int fieldIndex, int dateTimeGroupingType, int year, int month, int day, int hour, int minute, int second)Removes a date filter.
removeFilter(int fieldIndex)Remove the specific filter.
removeFilter(int fieldIndex, String criteria)Removes a filter for a filter column.
setRange(int row, int startColumn, int endColumn)Sets the range to which the specified AutoFilter applies.
setRange(String value)Represents the range to which the specified AutoFilter applies.
setShowFilterButton(boolean value)Indicates whether the AutoFilter button for this column is visible.
showAll()Unhide all rows.
toString()
wait()
wait(long arg0)
wait(long arg0, int arg1)

addDateFilter(int fieldIndex, int dateTimeGroupingType, int year, int month, int day, int hour, int minute, int second)

public void addDateFilter(int fieldIndex, int dateTimeGroupingType, int year, int month, int day, int hour, int minute, int second)

Adds a date filter.

Remarks

If DateTimeGroupingType is Year, only the param year effects. If DateTiemGroupingType is Month, only the param year and month effect.

Parameters:

ParameterTypeDescription
fieldIndexintThe integer offset of the field on which you want to base the filter (from the left of the list; the leftmost field is field 0).
dateTimeGroupingTypeintDateTimeGroupingType. The grouping type
yearintThe year.
monthintThe month.
dayintThe day.
hourintThe hour.
minuteintThe minute.
secondintThe second.

addFillColorFilter(int fieldIndex, int pattern, CellsColor foregroundColor, CellsColor backgroundColor)

public void addFillColorFilter(int fieldIndex, int pattern, CellsColor foregroundColor, CellsColor backgroundColor)

Adds a fill color filter.

Parameters:

ParameterTypeDescription
fieldIndexintThe integer offset of the field on which you want to base the filter (from the left of the list; the leftmost field is field 0).
patternintBackgroundType. The background pattern type.
foregroundColorCellsColorThe foreground color.
backgroundColorCellsColorThe background color.

addFilter(int fieldIndex, String criteria)

public void addFilter(int fieldIndex, String criteria)

Adds a filter for a filter column.

Remarks

MS Excel 2007 supports multiple selection in a filter column.

Parameters:

ParameterTypeDescription
fieldIndexintThe integer offset of the field on which you want to base the filter (from the left of the list; the leftmost field is field 0).
criteriajava.lang.StringThe specified criteria (a string; for example, “101”). It only can be null or be one of the cells’ value in this column.

addFontColorFilter(int fieldIndex, CellsColor color)

public void addFontColorFilter(int fieldIndex, CellsColor color)

Adds a font color filter.

Parameters:

ParameterTypeDescription
fieldIndexintThe integer offset of the field on which you want to base the filter (from the left of the list; the leftmost field is field 0).
colorCellsColorThe CellsColor object.

addIconFilter(int fieldIndex, int iconSetType, int iconId)

public void addIconFilter(int fieldIndex, int iconSetType, int iconId)

Adds an icon filter.

Remarks

Only supports to add the icon filter. Not supports checking which row is visible if the filter is icon filter.

Parameters:

ParameterTypeDescription
fieldIndexintThe integer offset of the field on which you want to base the filter (from the left of the list; the leftmost field is field 0).
iconSetTypeintIconSetType. The icon set type.
iconIdintThe icon id.

custom(int fieldIndex, int operatorType1, Object criteria1)

public void custom(int fieldIndex, int operatorType1, Object criteria1)

Filters a list with a custom criteria.

Parameters:

ParameterTypeDescription
fieldIndexintThe integer offset of the field on which you want to base the filter (from the left of the list; the leftmost field is field 0).
operatorType1intFilterOperatorType. The filter operator type
criteria1java.lang.ObjectThe custom criteria

custom(int fieldIndex, int operatorType1, Object criteria1, boolean isAnd, int operatorType2, Object criteria2)

public void custom(int fieldIndex, int operatorType1, Object criteria1, boolean isAnd, int operatorType2, Object criteria2)

Filters a list with custom criteria.

Parameters:

ParameterTypeDescription
fieldIndexintThe integer offset of the field on which you want to base the filter (from the left of the list; the leftmost field is field 0).
operatorType1intFilterOperatorType. The filter operator type
criteria1java.lang.ObjectThe custom criteria
isAndboolean
operatorType2intFilterOperatorType. The filter operator type
criteria2java.lang.ObjectThe custom criteria

dynamicFilter(int fieldIndex, int dynamicFilterType)

public void dynamicFilter(int fieldIndex, int dynamicFilterType)

Adds a dynamic filter.

Parameters:

ParameterTypeDescription
fieldIndexintThe integer offset of the field on which you want to base the filter (from the left of the list; the leftmost field is field 0).
dynamicFilterTypeintDynamicFilterType. Dynamic filter type.

equals(Object arg0)

public boolean equals(Object arg0)

Parameters:

ParameterTypeDescription
arg0java.lang.Object

Returns: boolean

filter(int fieldIndex, String criteria)

public void filter(int fieldIndex, String criteria)

Filters a list with specified criteria.

Remarks

Aspose.Cells will remove all other filter setting on this field as Ms Excel 97-2003.

Parameters:

ParameterTypeDescription
fieldIndexintThe integer offset of the field on which you want to base the filter (from the left of the list; the leftmost field is field 0).
criteriajava.lang.StringThe specified criteria (a string; for example, “101”).

filterTop10(int fieldIndex, boolean isTop, boolean isPercent, int itemCount)

public void filterTop10(int fieldIndex, boolean isTop, boolean isPercent, int itemCount)

Filter the top 10 item in the list

Parameters:

ParameterTypeDescription
fieldIndexintThe integer offset of the field on which you want to base the filter (from the left of the list; the leftmost field is field 0).
isTopbooleanIndicates whether filter from top or bottom
isPercentbooleanIndicates whether the items is percent or count
itemCountintThe item count

getCellArea()

public CellArea getCellArea()

Gets the CellArea where the specified AutoFilter applies to.

Returns: CellArea -

getClass()

public final native Class<?> getClass()

Returns: java.lang.Class

getFilterColumns()

public FilterColumnCollection getFilterColumns()

Gets the collection of the filter columns.

Returns: FilterColumnCollection

getRange()

public String getRange()

Represents the range to which the specified AutoFilter applies.

Returns: java.lang.String

getShowFilterButton()

public boolean getShowFilterButton()

Indicates whether the AutoFilter button for this column is visible.

Returns: boolean

getSorter()

public DataSorter getSorter()

Gets the data sorter.

Returns: DataSorter

hashCode()

public native int hashCode()

Returns: int

matchBlanks(int fieldIndex)

public void matchBlanks(int fieldIndex)

Match all blank cell in the list.

Parameters:

ParameterTypeDescription
fieldIndexintThe integer offset of the field on which you want to base the filter (from the left of the list; the leftmost field is field 0).

matchNonBlanks(int fieldIndex)

public void matchNonBlanks(int fieldIndex)

Match all not blank cell in the list.

Parameters:

ParameterTypeDescription
fieldIndexintThe integer offset of the field on which you want to base the filter (from the left of the list; the leftmost field is field 0).

notify()

public final native void notify()

notifyAll()

public final native void notifyAll()

refresh()

public int[] refresh()

Refresh auto filters to hide or unhide the rows.

Returns: int[] - Returns all hidden rows’ indexes.

refresh(boolean hideRows)

public int[] refresh(boolean hideRows)

Gets all hidden rows’ indexes.

Parameters:

ParameterTypeDescription
hideRowsbooleanIf true, hide the filtered rows.

Returns: int[] - Returns all hidden rows indexes.

removeDateFilter(int fieldIndex, int dateTimeGroupingType, int year, int month, int day, int hour, int minute, int second)

public void removeDateFilter(int fieldIndex, int dateTimeGroupingType, int year, int month, int day, int hour, int minute, int second)

Removes a date filter.

Remarks

If DateTimeGroupingType is Year, only the param year effects. If DateTiemGroupingType is Month, only the param year and month effect.

Parameters:

ParameterTypeDescription
fieldIndexintThe integer offset of the field on which you want to base the filter (from the left of the list; the leftmost field is field 0).
dateTimeGroupingTypeintDateTimeGroupingType. The grouping type
yearintThe year.
monthintThe month.
dayintThe day.
hourintThe hour.
minuteintThe minute.
secondintThe second.

removeFilter(int fieldIndex)

public void removeFilter(int fieldIndex)

Remove the specific filter.

Parameters:

ParameterTypeDescription
fieldIndexintThe specific filter index

removeFilter(int fieldIndex, String criteria)

public void removeFilter(int fieldIndex, String criteria)

Removes a filter for a filter column.

Parameters:

ParameterTypeDescription
fieldIndexintThe integer offset of the field on which you want to base the filter (from the left of the list; the leftmost field is field 0).
criteriajava.lang.StringThe specified criteria (a string; for example, “101”). It only can be null or be one of the cells’ value in this column.

setRange(int row, int startColumn, int endColumn)

public void setRange(int row, int startColumn, int endColumn)

Sets the range to which the specified AutoFilter applies.

Parameters:

ParameterTypeDescription
rowintRow index.
startColumnintStart column index.
endColumnintEnd column Index.

setRange(String value)

public void setRange(String value)

Represents the range to which the specified AutoFilter applies.

Parameters:

ParameterTypeDescription
valuejava.lang.String

setShowFilterButton(boolean value)

public void setShowFilterButton(boolean value)

Indicates whether the AutoFilter button for this column is visible.

Parameters:

ParameterTypeDescription
valueboolean

showAll()

public void showAll()

Unhide all rows.

toString()

public String toString()

Returns: java.lang.String

wait()

public final void wait()

wait(long arg0)

public final native void wait(long arg0)

Parameters:

ParameterTypeDescription
arg0long

wait(long arg0, int arg1)

public final void wait(long arg0, int arg1)

Parameters:

ParameterTypeDescription
arg0long
arg1int