Share via


Action-Schnittstelle

Stellt eine Smarttagaktion in einer Excel-Arbeitsmappe dar, die mit den Office-Entwicklungstools in Visual Studio angepasst wird.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Syntax

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

Der Action-Typ macht die folgenden Member verfügbar.

Eigenschaften

  Name Beschreibung
Öffentliche Eigenschaft Caption Ruft den Namen der Aktion ab, wie dieser im Smarttagmenü angezeigt wird, oder legt diesen Namen fest. (Von ActionBase geerbt.)

Zum Seitenanfang

Ereignisse

  Name Beschreibung
Öffentliches Ereignis BeforeCaptionShow Wird ausgelöst, nachdem der Benutzer auf das Smarttagsymbol geklickt hat und bevor das Smarttagmenü angezeigt wird.
Öffentliches Ereignis Click Wird ausgelöst, wenn im Smarttagmenü auf die Aktion geklickt wird.

Zum Seitenanfang

Hinweise

Aktionen sind die im Kontextmenü eines Smarttags verfügbaren Optionen, wenn ein Smarttag eines bestimmten Typs erkannt wird. Um eine Aktion zu erstellen, verwenden Sie die Globals.Factory.CreateAction-Methode zum Erstellen eines Action-Objekts. Weitere Informationen finden Sie unter Smarttagarchitektur.

Tipp

Diese Schnittstelle wird von der Visual Studio Tools for Office-Laufzeit implementiert. Es ist nicht vorgesehen, dass der Typ direkt vom Code implementiert wird. Weitere Informationen finden Sie unter Übersicht über die Visual Studio Tools for Office-Laufzeit.

Verwendung

Dieser Typ ist gedacht dazu, nur in Projekten für Excel 2007 verwendet zu werden. Smarttags sind in Excel 2010 veraltet. Weitere Informationen finden Sie unter Übersicht über Smarttags.

In dieser Dokumentation wird die Version dieses Typs beschrieben, der in Office-Projekten mit der Zielversion .NET Framework 4 verwendet wird. In Projekten mit der Zielversion .NET Framework 3.5 verfügt dieser Typ möglicherweise über unterschiedliche Member und die für diesen Typ bereitgestellten Codebeispiele funktionieren möglicherweise nicht. Dokumentation zu diesem Typ in Projekten mit der Zielversion .NET Framework 3.5 finden Sie im folgenden Verweisabschnitt in der Visual Studio 2008-Dokumentation: https://go.microsoft.com/fwlink/?LinkId=160658.

Beispiele

Im folgenden Codebeispiel wird ein SmartTag mit einer Action erstellt, die den Begriff "sale" und den regulären Ausdruck "[I|i]ssue\s\d{5,6}" erkennt. Die Smarttagaktion ändert die Menübeschriftung der Aktion zur Laufzeit und zeigt die Adresse des erkannten Texts an. Sie können das Beispiel testen, indem Sie das Wort "sale" in eine Zelle und die Zeichenfolge "issue 12345" in eine andere Zelle eingeben und dann die Smarttagaktionen ausführen.

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

Private Sub AddSmartTag()

    ' Create the smart tag for .NET Framework 4 projects.
    Dim smartTagDemo As Microsoft.Office.Tools.Excel.SmartTag = _
        Globals.Factory.CreateSmartTag(
        "www.microsoft.com/Demo#DemoSmartTag",
        "Demonstration Smart Tag")

    ' For .NET Framework 3.5 projects, use the following code to create the smart tag.
    ' Dim smartTagDemo As New  _
    '    Microsoft.Office.Tools.Excel.SmartTag( _
    '    "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}"))

    ' Create the action for .NET Framework 4 projects.
    displayAddress = Globals.Factory.CreateAction("To be replaced")

    ' For .NET Framework 3.5 projects, use the following code to create the action.
    ' displayAddress = New Microsoft.Office.Tools.Excel.Action("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()
{
    // Create the smart tag for .NET Framework 4 projects.
    Microsoft.Office.Tools.Excel.SmartTag smartTagDemo =
        Globals.Factory.CreateSmartTag(
            "www.microsoft.com/Demo#DemoSmartTag",
            "Demonstration Smart Tag");

    // For .NET Framework 3.5 projects, use the following code to create the smart tag.
    // Microsoft.Office.Tools.Excel.SmartTag smartTagDemo =
        // new Microsoft.Office.Tools.Excel.SmartTag(
        //     "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}"));

    // Create the action for .NET Framework 4 projects.
    displayAddress = Globals.Factory.CreateAction("To be replaced");

    // For .NET Framework 3.5 projects, use the following code to create the action.
    // displayAddress = new Microsoft.Office.Tools.Excel.Action("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(missing,
        missing, Excel.XlReferenceStyle.xlA1, missing, missing);
    System.Windows.Forms.MessageBox.Show("The recognized text '" + e.Text +
        "' is at range " + smartTagAddress);
}

Siehe auch

Referenz

Microsoft.Office.Tools.Excel-Namespace

SmartTag

Weitere Ressourcen

Smarttagarchitektur

Gewusst wie: Hinzufügen von Smarttags zu Excel-Arbeitsmappen

Gewusst wie: Erstellen von Smarttags mit benutzerdefinierten Erkennungen in Excel und .NET Framework 3.5