SmartTagRecognizeContext.PersistTag-Methode

Speichert Informationen zum Smarttag.

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

Syntax

'Declaration
Sub PersistTag ( _
    propertyBag As ISmartTagProperties _
)
void PersistTag(
    ISmartTagProperties propertyBag
)

Parameter

  • propertyBag
    Typ: Microsoft.Office.Interop.SmartTag.ISmartTagProperties
    Eine Eigenschaftensammlung, die Schlüssel-Wert-Paare für das Token enthält.Kann nullNULL-Verweis (Nothing in Visual Basic) sein.

Ausnahmen

Ausnahme Bedingung
InvalidOperationException

PersistTag wurde nicht von der Recognize-Methode aufgerufen.

Hinweise

Rufen Sie PersistTag aus einer Implementierung der Recognize-Methode auf, um anzugeben, dass das Smarttag im Text gefunden wurde. Verwenden Sie den propertyBag-Parameter, um für beliebige benutzerdefinierte Eigenschaften für das Smarttag einen Commit auszuführen. Sie können die Aktion mit diesen Eigenschaften anpassen, wenn ein Element aus dem Kontextmenü des Smarttags ausgewählt wird.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie PersistTag aus einer Implementierung der Recognize-Methode aufgerufen wird. Bei dieser Implementierung wird jeder Smarttagbegriff mit dem Inhalt der Zelle verglichen. Im Code wird für jeden Smarttagbegriff in der Zelle eine benutzerdefinierte Smarttageigenschaft hinzugefügt, und dann wird die PersistTag-Methode zum Erkennen des Smarttags verwendet. In diesem Beispiel wird davon ausgegangen, dass Sie von der Registerkarte .NET im Dialogfeld Verweis hinzufügen einen Verweis auf Microsoft.Office.Interop.SmartTag hinzugefügt haben. Dieses Codebeispiel ist Teil eines umfangreicheren Beispiels für die ISmartTagExtension-Schnittstelle.

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

.NET Framework-Sicherheit

Siehe auch

Referenz

SmartTagRecognizeContext Schnittstelle

Microsoft.Office.Tools.Excel-Namespace