Compartir a través de


SmartTagRecognizeContext.PersistTag (Método)

Almacena información sobre la etiqueta inteligente.

Espacio de nombres:  Microsoft.Office.Tools.Excel
Ensamblado:  Microsoft.Office.Tools.Excel (en Microsoft.Office.Tools.Excel.dll)

Sintaxis

'Declaración
Sub PersistTag ( _
    propertyBag As ISmartTagProperties _
)
void PersistTag(
    ISmartTagProperties propertyBag
)

Parámetros

  • propertyBag
    Tipo: Microsoft.Office.Interop.SmartTag.ISmartTagProperties
    Bolsa de propiedades que contiene pares de clave y valor para el símbolo (token).Puede ser nullreferencia null (Nothing en Visual Basic).

Excepciones

Excepción Condición
InvalidOperationException

No se llamó a PersistTag desde el método Recognize.

Comentarios

Llame a PersistTag desde una implementación del método Recognize para indicar que la etiqueta inteligente se encontró en el texto. Utilice el parámetro propertyBag para confirmar cualquier propiedad personalizada para la etiqueta inteligente. Puede utilizar estas propiedades para personalizar la acción tomada cuando un elemento del menú contextual de la etiqueta inteligente está seleccionado.

Ejemplos

En el ejemplo de código siguiente se muestra cómo llamar a PersistTag desde una implementación del método Recognize. Esta implementación compara cada término de la etiqueta inteligente con el contenido de la celda. Para cada término de etiqueta inteligente de la celda, el código agrega una propiedad de etiqueta inteligente personalizada y, a continuación, usa el método PersistTag para reconocer la etiqueta inteligente. En este ejemplo se supone que se ha agregado una referencia a Microsoft.Office.Interop.SmartTag desde la pestaña .NET del cuadro de diálogo Agregar referencia. Este ejemplo de código forma parte de un ejemplo más extenso relativo a la interfaz 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;
        }
    }
}

Seguridad de .NET Framework

Vea también

Referencia

SmartTagRecognizeContext Interfaz

Microsoft.Office.Tools.Excel (Espacio de nombres)