本文為機器翻譯文章。如需檢視英文版,請選取 [原文] 核取方塊。您也可以將滑鼠指標移到文字上,即可在快顯視窗顯示英文原文。
譯文
原文

WorksheetBase.AutoFilter 屬性

 

取得 Microsoft.Office.Interop.Excel.AutoFilter,它提供工作表上已篩選清單的相關資訊 (如果已啟用篩選功能)。 如果已關閉篩選會取得 null

命名空間:   Microsoft.Office.Tools.Excel
組件:  Microsoft.Office.Tools.Excel.v4.0.Utilities (於 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

public AutoFilter AutoFilter { get; }

屬性值

Type: Microsoft.Office.Interop.Excel.AutoFilter

Microsoft.Office.Interop.Excel.AutoFilter,它提供工作表上已篩選清單的相關資訊 (如果啟用篩選功能);否則為 null

To programmatically enable filtering, use the M:Microsoft.Office.Interop.Excel.Range.AutoFilter(System.Object,System.Object,Microsoft.Office.Interop.Excel.XlAutoFilterOperator,System.Object,System.Object) method of the T:Microsoft.Office.Interop.Excel.Range object or the M:Microsoft.Office.Tools.Excel.NamedRange.AutoFilter(System.Object,System.Object,Microsoft.Office.Interop.Excel.XlAutoFilterOperator,System.Object,System.Object) method of a T:Microsoft.Office.Tools.Excel.NamedRange object.

The following code example creates a filtered list of fruits in a T:Microsoft.Office.Interop.Excel.Range, and then uses the P:Microsoft.Office.Tools.Excel.WorksheetBase.AutoFilter property to display the filter criteria for the list. The example then prompts the user to turn off the filter by using the P:Microsoft.Office.Tools.Excel.WorksheetBase.AutoFilterMode property, and finally uses the P:Microsoft.Office.Tools.Excel.WorksheetBase.FilterMode property to display whether the worksheet has a filtered list.

This example is for a document-level customization.

private void ActivateAutoFilter()
{
    this.Range["A1"].Value2 = "Fruits";
    this.Range["A2"].Value2 = "Banana";
    this.Range["A3"].Value2 = "Apple";
    this.Range["A4"].Value2 = "Banana";
    this.Range["A5"].Value2 = "Orange";
    this.Range["A6"].Value2 = "Apple";
    this.Range["A7"].Value2 = "Orange";

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

    NamedRange1.AutoFilter(1, "Apple",
       Excel.XlAutoFilterOperator.xlAnd, 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");
    }
}
回到頁首
顯示: