Share via


SmartTagRecognizeContext.PersistTag, méthode

Stocke des informations relatives à la balise active.

Espace de noms :  Microsoft.Office.Tools.Excel
Assembly :  Microsoft.Office.Tools.Excel (dans Microsoft.Office.Tools.Excel.dll)

Syntaxe

'Déclaration
Sub PersistTag ( _
    propertyBag As ISmartTagProperties _
)
void PersistTag(
    ISmartTagProperties propertyBag
)

Paramètres

  • propertyBag
    Type : Microsoft.Office.Interop.SmartTag.ISmartTagProperties
    Sac de propriété qui contient les paires valeur-clé du jeton.Peut être nullune référence null (Nothing en Visual Basic).

Exceptions

Exception Condition
InvalidOperationException

PersistTag n'a pas été appelé à partir de la méthode Recognize.

Notes

Appelez PersistTag à partir d'une implémentation de la méthode Recognize pour indiquer que la balise active a été trouvée dans le texte. Utilisez le paramètre propertyBag pour valider toute propriété personnalisée pour la balise active. Vous pouvez utiliser ces propriétés pour personnaliser l'action effectuée lorsqu'un élément du menu contextuel de la balise active est sélectionné.

Exemples

L'exemple de code suivant montre comment appeler PersistTag à partir d'une implémentation de la méthode Recognize. Cette implémentation compare chaque terme de balise active au contenu de la cellule. Pour chaque terme de balise active dans la cellule, le code ajoute une propriété de balise active personnalisée puis utilise la méthode PersistTag pour reconnaître la balise active. Cet exemple suppose que vous avez ajouté une référence à Microsoft.Office.Interop.SmartTag à partir de l'onglet .NET de la boîte de dialogue Ajouter une référence. Cet exemple de code fait partie d'un exemple plus complet fourni pour l'interface ISmartTagExtension.

Private Sub Recognize(ByVal text As String, 
    ByVal site As ISmartTagRecognizerSite, ByVal tokenList As ISmartTagTokenList, 
    ByVal context As SmartTagRecognizeContext) Implements ISmartTagExtension.Recognize

    ' Determine whether each smart tag term exists in the document text.
    Dim Term As String
    For Each Term In smartTagDemo.Terms

        ' Search the cell text for the first instance of 
        ' the current smart tag term.
        Dim index As Integer = context.CellText.IndexOf(Term, 0)

        If (index >= 0) Then

            ' Create a smart tag token and a property bag for the 
            ' recognized term.
            Dim propertyBag As ISmartTagProperties = site.GetNewPropertyBag()

            ' Write a new property value.
            Dim key As String = "Key1"
            propertyBag.Write(key, DateTime.Now)

            ' Attach the smart tag to the term in the document.
            context.PersistTag(propertyBag)

            ' This implementation only finds the first instance
            ' of a smart tag term in the cell. 
            Exit For
        End If
    Next
End Sub
void ISmartTagExtension.Recognize(string text, ISmartTagRecognizerSite site, 
    ISmartTagTokenList tokenList, SmartTagRecognizeContext context)
{

    // Determine whether each smart tag term exists in the document text.
    foreach (string term in smartTagDemo.Terms)
    {
        // Search the cell text for the first instance of the current smart tag term.
        int index = context.CellText.IndexOf(term, 0);

        if (index >= 0)
        {
            // Create a smart tag token and a property bag for the recognized term.
            ISmartTagProperties propertyBag = site.GetNewPropertyBag();

            // Write a new property value.                 
            string key = "Key1";
            propertyBag.Write(key, DateTime.Now.ToString());

            // Attach the smart tag to the term in the document
            context.PersistTag(propertyBag);

            // This implementation only finds the first instance of a 
            // smart tag term in the cell. 
            break;
        }
    }
}

Sécurité .NET Framework

Voir aussi

Référence

SmartTagRecognizeContext Interface

Microsoft.Office.Tools.Excel, espace de noms