次の方法で共有


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
    認識された項目を検索するテキストを、トークンのリストに分解したもの。
  • context
    型: Microsoft.Office.Tools.Excel.SmartTagRecognizeContext
    スマート タグが検出されたことを示すために呼び出すことができるメソッドと、レコグナイザーに送信されるセル内のテキストを提供するオブジェクト。

解説

このメソッドは、認識された用語をテキストから検索するために 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 名前空間