SmartTagRecognizeContext.PersistTag 方法

存储有关智能标记的信息。此类型或成员只适合在 2007 Microsoft Office system 项目中使用。Office 2010 中已弃用智能标记。
.

命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel(在 Microsoft.Office.Tools.Excel.dll 中)

语法

声明
Sub PersistTag ( _
    propertyBag As ISmartTagProperties _
)
void PersistTag(
    ISmartTagProperties propertyBag
)

参数

  • propertyBag
    类型:Microsoft.Office.Interop.SmartTag.ISmartTagProperties
    一个属性包,包含标记的键/值对。可以为 nullnull 引用(在 Visual Basic 中为 Nothing)。

异常

异常 条件
InvalidOperationException

PersistTag 不是从 Recognize 方法中调用的。

备注

Recognize 方法的实现中调用 PersistTag,以指示在文本中找到了智能标记。使用 propertyBag 参数提交智能标记的任何自定义属性。可以使用这些属性来自定义在从智能标记快捷菜单选择某个项目时所执行的操作。

示例

下面的代码示例演示如何从 Recognize 方法的实现中调用 PersistTag。此实现将每个智能标记术语与该单元格的内容进行比较。对于该单元格中的每个智能标记术语,该代码添加一个自定义智能标记属性,然后使用 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

    ' 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;
        }
    }
}

.NET Framework 安全性

请参见

参考

SmartTagRecognizeContext 接口

Microsoft.Office.Tools.Excel 命名空间