WorksheetBase.FilterMode 属性

获取一个值,该值指示工作表是否正在主动筛选数据。

命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel.v4.0.Utilities(在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)

语法

声明
Public ReadOnly Property FilterMode As Boolean
    Get
public bool FilterMode { get; }

属性值

类型:System.Boolean
如果工作表正在主动筛选数据,则为 true;否则为 false。

备注

若要确定当前时候启用了筛选功能(即,工作表上是否显示筛选器下拉箭头),请使用 AutoFilterMode 属性。

若要启用筛选并创建筛选列表,请使用 Range 对象的 AutoFilter 方法或使用 NamedRange 对象的 AutoFilter 方法。

如果工作表包含一个其中有隐藏行的已筛选的列表,则为此属性为 true。

示例

下面的代码示例在一个 Range 中创建一个经过筛选的水果列表,然后使用 AutoFilter 属性显示该列表的筛选条件。 然后,此示例提示用户通过使用 AutoFilterMode 属性关闭筛选器,最后使用 FilterMode 属性显示工作表是否具有已筛选的列表。

此示例针对的是文档级自定义项。

Private Sub ActivateAutoFilter()
    Me.Range("A1").Value2 = "Fruits"
    Me.Range("A2").Value2 = "Banana"
    Me.Range("A3").Value2 = "Apple"
    Me.Range("A4").Value2 = "Banana"
    Me.Range("A5").Value2 = "Orange"
    Me.Range("A6").Value2 = "Apple"
    Me.Range("A7").Value2 = "Orange"

    Dim NamedRange1 As Microsoft.Office.Tools.Excel.NamedRange = _
        Me.Controls.AddNamedRange(Me.Range("A1", "A7"), "NamedRange1")

    NamedRange1.AutoFilter(1, "Apple", Excel.XlAutoFilterOperator.xlAnd, _
        VisibleDropDown:=True)

    MsgBox("The current criteria for the AutoFilter is: " & _
        Me.AutoFilter.Filters(1).Criteria1.ToString())

    If Me.AutoFilterMode Then
        If DialogResult.Yes = MessageBox.Show("Would you like to " & _
            "turn off the filter?", "Example", MessageBoxButtons.YesNo) Then
            Me.AutoFilterMode = False
        End If
    End If

    If Me.FilterMode Then
        MsgBox("The worksheet has a filtered list.")
    Else
        MsgBox("The worksheet does not have a filtered list")
    End If
End Sub
private void ActivateAutoFilter()
{
    this.Range["A1", missing].Value2 = "Fruits";
    this.Range["A2", missing].Value2 = "Banana";
    this.Range["A3", missing].Value2 = "Apple";
    this.Range["A4", missing].Value2 = "Banana";
    this.Range["A5", missing].Value2 = "Orange";
    this.Range["A6", missing].Value2 = "Apple";
    this.Range["A7", missing].Value2 = "Orange";

    Microsoft.Office.Tools.Excel.NamedRange NamedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", "A7"],
        "NamedRange1");

    NamedRange1.AutoFilter(1, "Apple",
       Excel.XlAutoFilterOperator.xlAnd, missing, true);

    MessageBox.Show("The current criteria for the AutoFilter is: " +
        this.AutoFilter.Filters[1].Criteria1.ToString());

    if (this.AutoFilterMode)
    {
        if (DialogResult.Yes == MessageBox.Show("Would you like to " +
            "turn off the filter?", "Example", MessageBoxButtons.YesNo))
        {
            this.AutoFilterMode = false;
        }
    }

    if (this.FilterMode)
    {
        MessageBox.Show("The worksheet has a filtered list.");
    }
    else
    {
        MessageBox.Show("The worksheet does not have a filtered list");
    }
}

.NET Framework 安全性

请参见

参考

WorksheetBase 类

Microsoft.Office.Tools.Excel 命名空间