Share via


Interfaccia SmartTag

Rappresenta uno smart tag in una cartella di lavoro di Excel personalizzato tramite gli Strumenti di sviluppo di Microsoft Office per Visual Studio.

Spazio dei nomi:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Sintassi

'Dichiarazione
<GuidAttribute("f210dc7f-21b5-475e-ae31-76a9b06b9835")> _
Public Interface SmartTag _
    Inherits SmartTagBase
[GuidAttribute("f210dc7f-21b5-475e-ae31-76a9b06b9835")]
public interface SmartTag : SmartTagBase

Il tipo SmartTag espone i seguenti membri.

Proprietà

  Nome Descrizione
Proprietà pubblica Actions Ottiene o imposta una matrice di azioni esposte dallo smart tag. (Ereditato da SmartTagBase)
Proprietà pubblica Caption Ottiene il nome dello smart tag. (Ereditato da SmartTagBase)
Proprietà pubblica DefaultExtension Ottiene l'estensione predefinita per l'oggetto SmartTag.
Proprietà pubblica Expressions Ottiene l'insieme di espressioni regolari che verranno riconosciute dallo smart tag. (Ereditato da SmartTagBase)
Proprietà pubblica Extension Ottiene un'estensione personalizzata per l'oggetto SmartTag.
Proprietà pubblica SmartTagType Ottiene uno spazio dei nomi che funge da identificatore univoco per lo smart tag. (Ereditato da SmartTagBase)
Proprietà pubblica Terms Ottiene l'insieme di stringhe letterali che verranno riconosciute dallo smart tag. (Ereditato da SmartTagBase)

In alto

Metodi

  Nome Descrizione
Metodo pubblico Remove Rimuove un sistema di riconoscimento di espressioni regolari dallo smart tag. (Ereditato da SmartTagBase)

In alto

Note

Per creare smart tag, utilizzare il metodo Globals.Factory.CreateSmartTag per creare un oggetto SmartTag. Per informazioni, vedere Architettura degli smart tag.

Nota

Questa interfaccia è implementata da Visual Studio Tools per Office Runtime. Non deve essere implementata nel codice. Per ulteriori informazioni, vedere Cenni preliminari su Visual Studio Tools per Office Runtime.

Utilizzo

Questo tipo deve essere utilizzato solo nei progetti per Excel 2007. Gli smart tag sono deprecati in Excel 2010. Per ulteriori informazioni, vedere Cenni preliminari sugli smart tag.

Nella presente documentazione viene descritta la versione di questo tipo utilizzata nei progetti di Office destinati a .NET Framework 4. Nei progetti destinati a .NET Framework 3.5, questo tipo potrebbe avere membri diversi e gli esempi di codice forniti per il tipo potrebbero non funzionare. Per la documentazione relativa a questo tipo nei progetti destinati a .NET Framework 3.5, vedere la sezione di riferimento seguente nella documentazione di Visual Studio 2008: https://go.microsoft.com/fwlink/?LinkId=160658.

Esempi

Nell'esempio di codice riportato di seguito viene illustrato come creare un oggetto SmartTag con un oggetto Action per il riconoscimento del termine "sale" e dell'espressione regolare "[I|i]ssue\s\d{5,6}". L'azione modifica la didascalia di menu dell'azione in fase di esecuzione e visualizza l'indirizzo del testo riconosciuto. Per verificare l'esempio digitare la parola "sale" in una cella e la stringa "issue 12345" in un'altra, quindi provare l'azione smart tag.

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);
}

Vedere anche

Riferimenti

Spazio dei nomi Microsoft.Office.Tools.Excel

Altre risorse

Architettura degli smart tag

Procedura: aggiungere smart tag a cartelle di lavoro di Excel

Procedura: creare smart tag con sistemi di riconoscimento personalizzati in Excel e .NET Framework 3.5