Compartir a través de


ISmartTagExtension.Recognize (Método)

Busca texto en la celda de términos reconocidos.

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

Sintaxis

'Declaración
Sub Recognize ( _
    text As String, _
    site As ISmartTagRecognizerSite, _
    tokenList As ISmartTagTokenList, _
    context As SmartTagRecognizeContext _
)
void Recognize(
    string text,
    ISmartTagRecognizerSite site,
    ISmartTagTokenList tokenList,
    SmartTagRecognizeContext context
)

Parámetros

  • text
    Tipo: System.String
    Texto en el que se van a buscar los términos reconocidos.
  • site
    Tipo: Microsoft.Office.Interop.SmartTag.ISmartTagRecognizerSite
    Ubicación del texto en el libro o documento.
  • tokenList
    Tipo: Microsoft.Office.Interop.SmartTag.ISmartTagTokenList
    Texto en el que se van a buscar los términos reconocidos, desglosados en una lista de símbolos (token).

Comentarios

Motor en tiempo de ejecución de Microsoft Visual Studio Tools para Office llama a este método para buscar términos reconocidos en el texto. Implemente este método si desea incorporar sus propios algoritmos de búsqueda para ejecutarlos además de los reconocedores estándar.

Ejemplos

En el ejemplo de código siguiente se muestra cómo se implementa el método Recognize. Esta implementación compara cada término de la etiqueta inteligente con el contenido de una celda en una hoja de cálculo de Microsoft Office Excel. Si se encuentra un término de etiqueta inteligente en la celda, el código agrega una propiedad de etiqueta inteligente personalizada a la etiqueta inteligente y, a continuación, utiliza el método PersistTag para reconocerla. 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

    For Each term As String In smartTagDemo.Terms
        ' Search the text for the current smart tag term.
        Dim index As Integer = text.IndexOf(term, 0)

        While (index >= 0)
            ' 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.ToString())

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

            ' Increment the index and then find the next instance of the smart tag term.
            index += term.Length
            index = text.IndexOf(term, index)
        End While
    Next
End Sub
void ISmartTagExtension.Recognize(string text, ISmartTagRecognizerSite site, ISmartTagTokenList tokenList, 
    SmartTagRecognizeContext context)
{

    foreach (string term in smartTagDemo.Terms)
    {
        // Search the text for the current smart tag term.
        int index = text.IndexOf(term, 0);

        while (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(index, term.Length, propertyBag);

            // Increment the index and then find the next instance of the smart tag term.
            index += term.Length;
            index = text.IndexOf(term, index);
        }
    }
}

Seguridad de .NET Framework

Vea también

Referencia

ISmartTagExtension Interfaz

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