SmartTag.PersistTag 方法 () (2007 system)

更新:2007 年 11 月

存储有关智能标记的信息。

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

语法

声明
Protected Sub PersistTag ( _
    propertyBag As ISmartTagProperties _
)
用法
Dim propertyBag As ISmartTagProperties

Me.PersistTag(propertyBag)
protected void PersistTag(
    ISmartTagProperties propertyBag
)

参数

  • propertyBag
    类型:ISmartTagProperties

    一个属性包,包含标记的键/值对。可以为 nullnull 引用(在 Visual Basic 中为 Nothing)。

异常

异常 条件
InvalidOperationException

PersistTag 不是从 Recognize 调用的。

备注

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

示例

下面的代码示例演示如何重写从 Microsoft.Office.Tools.Excel.SmartTag 派生的类中的 Recognize 方法。Recognize 的此实现将每个智能标记术语与该单元格的内容进行比较。如果在该单元格中找到某个智能标记术语,该代码添加一个自定义智能标记属性,然后使用 PersistTag(ISmartTagProperties) 方法识别该智能标记。此示例假设您已从“添加引用”对话框的“COM”选项卡添加一个对“Microsoft Smart Tags 2.0 类型库”的引用。此代码示例摘自为 SmartTag 类提供的一个更大示例。

Protected Overrides Sub Recognize(ByVal text As String, _
    ByVal site As ISmartTagRecognizerSite, _
    ByVal tokenList As ISmartTagTokenList)

    ' Determine whether each smart tag term exists in 
    ' the document text.
    Dim Term As String
    For Each Term In Me.Terms

        ' Search the cell text for the first instance of 
        ' the current smart tag term.
        Dim index As Integer = Me.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
            Me.PersistTag(propertyBag)

            ' This implementation only finds the first instance
            ' of a smart tag term in the cell. 
            Exit For
        End If
    Next
End Sub
protected override void Recognize(string text, 
    ISmartTagRecognizerSite site, ISmartTagTokenList tokenList)
{
    // Determine whether each smart tag term exists in 
    // the document text.
    foreach (string term in this.Terms)
    {
        // Search the cell text for the first instance of 
        // the current smart tag term.
        int index = this.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
            this.PersistTag(propertyBag);

            // This implementation only finds the first instance
            // of a smart tag term in the cell. 
            break;
        }
    }
}

权限

另请参见

参考

SmartTag 类

SmartTag 成员

PersistTag 重载

Microsoft.Office.Tools.Excel 命名空间

Properties