Action 介面

表示使用 Visual Studio 的 Office 開發工具所自訂之 Excel 活頁簿中的智慧標籤動作。

命名空間:  Microsoft.Office.Tools.Excel
組件:  Microsoft.Office.Tools.Excel (在 Microsoft.Office.Tools.Excel.dll 中)

語法

'宣告
<GuidAttribute("37e25b46-6941-4833-9b08-e692cf461982")> _
Public Interface Action _
    Inherits ActionBase
[GuidAttribute("37e25b46-6941-4833-9b08-e692cf461982")]
public interface Action : ActionBase

Action 型別會公開下列成員。

屬性

  名稱 說明
公用屬性 Caption 取得或設定動作名稱,如智慧標籤功能表上所顯示。 這個型別或成員僅適用於 2007 Microsoft Office system 專案。智慧標籤在 Office 2010 中已被取代。
. (繼承自 ActionBase)。

回頁首

事件

  名稱 說明
公用事件 BeforeCaptionShow 在使用者按一下智慧標籤圖示之後,顯示智慧標籤功能表之前發生。 這個型別或成員僅適用於 2007 Microsoft Office system 專案。智慧標籤在 Office 2010 中已被取代。
.
公用事件 Click 在智慧標籤功能表上按一下時發生。 這個型別或成員僅適用於 2007 Microsoft Office system 專案。智慧標籤在 Office 2010 中已被取代。
.

回頁首

備註

動作是指系統在辨認智慧標籤的型別後,出現在智慧標籤捷徑功能表上的可用選項。 若要建立動作,請使用 Globals.Factory.CreateAction 方法建立 Action 物件。

注意事項注意事項

這個界面是由 Visual Studio Tools for Office Runtime 實作,並不能實作於您的程式碼中。如需詳細資訊,請參閱 Visual Studio Tools for Office Runtime 概觀

使用方式

這個型別僅適用於 Excel 2007 專案。 只有在 Excel 2010 中已被取代。

本文件說明此型別用於以 .NET Framework 4 和 .NET Framework 4.5 為目標之 Office 專案的版本。在以 .NET Framework 3.5 為目標的專案中,此型別可能會有不同的成員,而為此型別提供的程式碼範例可能無法運作。如需此型別在以 .NET Framework 3.5 為目標之專案中的相關文件,請參閱下列 Visual Studio 2008 文件中的參考章節:https://go.microsoft.com/fwlink/?LinkId=160658 (英文)。

範例

下列程式碼範例會建立具備 Action 的 SmartTag,此智慧標籤會辨認 "sale" 詞彙和規則運算式 (Regular Expression) "[I|i]ssue\s\d{5,6}"。 動作會修改在執行階段時動作的功能表標題,並且顯示已辨認文字的位址。 若要測試範例,請在一個儲存格內輸入詞彙 "sale",另一個儲存格內輸入 "issue 12345",然後嘗試執行智慧標籤動作。

WithEvents displayAddress As Microsoft.Office.Tools.Excel.Action

Private Sub AddSmartTag()

    Dim smartTagDemo As Microsoft.Office.Tools.Excel.SmartTag = _
        Globals.Factory.CreateSmartTag(
        "www.microsoft.com/Demo#DemoSmartTag",
        "Demonstration Smart Tag")

    ' Specify a term and an expression to recognize.
    smartTagDemo.Terms.Add("sale")
    smartTagDemo.Expressions.Add( _
        New System.Text.RegularExpressions.Regex( _
        "[I|i]ssue\s\d{5,6}"))

    displayAddress = Globals.Factory.CreateAction("To be replaced")

    ' Add the action to the smart tag.
    smartTagDemo.Actions = New Microsoft.Office.Tools.Excel.Action() { _
            displayAddress}

    ' Add the smart tag.
    Me.VstoSmartTags.Add(smartTagDemo)
End Sub

Private Sub DisplayAddress_BeforeCaptionShow(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Excel.ActionEventArgs) _
    Handles DisplayAddress.BeforeCaptionShow

    Dim clickedAction As Microsoft.Office.Tools.Excel.Action = _
        TryCast(sender, Microsoft.Office.Tools.Excel.Action)

    If clickedAction IsNot Nothing Then
        clickedAction.Caption = "Display the address of " & e.Text
    End If
End Sub

Private Sub DisplayAddress_Click(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Excel.ActionEventArgs) _
    Handles DisplayAddress.Click

    Dim smartTagAddress As String = e.Range.Address( _
        ReferenceStyle:=Excel.XlReferenceStyle.xlA1)
    MsgBox("The recognized text '" & e.Text & _
            "' is at range " & smartTagAddress)
End Sub
private Microsoft.Office.Tools.Excel.Action displayAddress;

private void AddSmartTag()
{
    Microsoft.Office.Tools.Excel.SmartTag smartTagDemo =
        Globals.Factory.CreateSmartTag(
            "www.microsoft.com/Demo#DemoSmartTag",
            "Demonstration Smart Tag");

    // Specify a term and an expression to recognize.
    smartTagDemo.Terms.Add("sale");
    smartTagDemo.Expressions.Add(
        new System.Text.RegularExpressions.Regex(
        @"[I|i]ssue\s\d{5,6}"));

    displayAddress = Globals.Factory.CreateAction("To be replaced");


    // Add the action to the smart tag.
    smartTagDemo.Actions = new Microsoft.Office.Tools.Excel.Action[] { 
        displayAddress };

    // Add the smart tag.
    this.VstoSmartTags.Add(smartTagDemo);

    displayAddress.BeforeCaptionShow += new 
        Microsoft.Office.Tools.Excel.BeforeCaptionShowEventHandler(
        DisplayAddress_BeforeCaptionShow);

    displayAddress.Click += new 
        Microsoft.Office.Tools.Excel.ActionClickEventHandler(
        DisplayAddress_Click);
}

void DisplayAddress_BeforeCaptionShow(object sender, 
    Microsoft.Office.Tools.Excel.ActionEventArgs e)
{
    Microsoft.Office.Tools.Excel.Action clickedAction =
        sender as Microsoft.Office.Tools.Excel.Action;

    if (clickedAction != null)
    {
        clickedAction.Caption = "Display the address of " +
            e.Text;
    }
}

void DisplayAddress_Click(object sender, 
    Microsoft.Office.Tools.Excel.ActionEventArgs e)
{
    string smartTagAddress = e.Range.get_Address(Excel.XlReferenceStyle.xlA1);
    System.Windows.Forms.MessageBox.Show("The recognized text '" + e.Text +
        "' is at range " + smartTagAddress);
}

請參閱

參考

Microsoft.Office.Tools.Excel 命名空間

SmartTag