Condividi tramite


Metodo SmartTagRecognizeContext.PersistTag

Archivia le informazioni sullo smart tag. Questo tipo o membro deve essere utilizzato solo nei progetti per Microsoft Office System 2007. Gli smart tag sono deprecati in Office 2010.
.

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

Sintassi

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

Parametri

  • propertyBag
    Tipo: Microsoft.Office.Interop.SmartTag.ISmartTagProperties
    Un contenitore di proprietà che contiene coppie chiave/valore per il token.può essere nullriferimento null (Nothing in Visual Basic).

Eccezioni

Eccezione Condizione
InvalidOperationException

Recognize non è stato chiamato dal diPersistTag metodo.

Note

chiamata Recognize da un'implementazione di di PersistTag metodo per indicare che lo smart tag è stato trovato il testo. utilizzare propertyBag parametro per eseguire il commit di tutte le proprietà personalizzate per lo smart tag. È possibile utilizzare queste proprietà per personalizzare le azioni eseguite quando un elemento dal menu di scelta rapida dello smart tag viene selezionato.

Esempi

Nell'esempio di codice seguente viene illustrato come chiamare Recognize da un'implementazione di di PersistTag metodo. Questa implementazione confronta ogni condizione dello smart tag al contenuto della cella. Per ogni condizione smart tag nella cella, il codice aggiunge una proprietà personalizzata dello smart tag e quindi utilizzare PersistTag metodo per riconoscere lo smart tag. Questo esempio si presuppone che sia stato aggiunto un riferimento a Microsoft.Office.Interop.SmartTag da .NET scheda di aggiungere il riferimento finestra di dialogo. Questo esempio di codice fa parte di un esempio più esaustivo fornito per ISmartTagExtension interfaccia.

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

Sicurezza di .NET Framework

Vedere anche

Riferimenti

SmartTagRecognizeContext Interfaccia

Spazio dei nomi Microsoft.Office.Tools.Excel