다음을 통해 공유


ISmartTagExtension.Recognize 메서드

셀의 텍스트에서 인식된 용어를 검색합니다.

네임스페이스:  Microsoft.Office.Tools.Excel
어셈블리:  Microsoft.Office.Tools.Excel(Microsoft.Office.Tools.Excel.dll)

구문

‘선언
Sub Recognize ( _
    text As String, _
    site As ISmartTagRecognizerSite, _
    tokenList As ISmartTagTokenList, _
    context As SmartTagRecognizeContext _
)
void Recognize(
    string text,
    ISmartTagRecognizerSite site,
    ISmartTagTokenList tokenList,
    SmartTagRecognizeContext context
)

매개 변수

  • text
    형식: System.String
    인식된 용어를 검색할 텍스트입니다.
  • site
    형식: Microsoft.Office.Interop.SmartTag.ISmartTagRecognizerSite
    통합 문서나 문서에 있는 텍스트의 위치입니다.
  • tokenList
    형식: Microsoft.Office.Interop.SmartTag.ISmartTagTokenList
    인식된 용어를 검색할 텍스트이며 토큰 목록으로 나누어집니다.

설명

이 메서드는 텍스트에서 인식된 용어를 검색하기 위해 Microsoft Visual Studio Tools for Office Runtime에서 호출됩니다. 표준 인식자와 자체의 검색 알고리즘을 통합하여 실행하려는 경우 이 메서드를 구현합니다.

예제

다음 코드 예제에서는 Recognize 메서드를 구현하는 방법을 보여 줍니다. 이 구현에서는 각 스마트 태그 용어를 Microsoft Office Excel 워크시트의 셀 내용과 비교합니다. 셀에 스마트 태그 용어가 있으면 코드가 사용자 지정 스마트 태그 속성을 스마트 태그에 추가한 다음 PersistTag 메서드를 호출하여 스마트 태그를 인식합니다. 이 예제에서는 참조 추가 대화 상자의 .NET 탭에서 Microsoft.Office.Interop.SmartTag에 대한 참조를 추가한 것으로 가정합니다. 이 코드 예제는 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);
        }
    }
}

.NET Framework 보안

  • 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.

참고 항목

참조

ISmartTagExtension 인터페이스

Microsoft.Office.Tools.Excel 네임스페이스