在单元格的文本中搜索识别的术语。
命名空间:  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 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。