表示 Word 或 Excel 解决方案中的智能标记的集合,该解决方案是使用 Visual Studio 中的 Office 开发工具创建的。
命名空间:  Microsoft.Office.Tools
程序集:  Microsoft.Office.Tools.Common(在 Microsoft.Office.Tools.Common.dll 中)
语法
声明
<GuidAttribute("30a90086-8c89-4e19-8299-47765d808408")> _
Public Interface SmartTagCollection _
    Inherits IEnumerable, IDisposable
[GuidAttribute("30a90086-8c89-4e19-8299-47765d808408")]
public interface SmartTagCollection : IEnumerable, 
    IDisposable
SmartTagCollection 类型公开以下成员。
属性
| 名称 | 说明 | |
|---|---|---|
| .gif) | Item | 获取指定索引处的智能标记。 | 
页首
方法
| 名称 | 说明 | |
|---|---|---|
| .gif) | Add | 将智能标记添加到 SmartTagCollection 的末尾。 | 
| .gif) | AddRange | 将智能标记数组添加到 SmartTagCollection 的末尾。 | 
| .gif) | BeginInit | 基础结构。 | 
| .gif) | Contains | 确定 SmartTagCollection 是否包含特定的智能标记。 | 
| .gif) | CopyTo | 将 SmartTagCollection 中的智能标记复制到一个一维的智能标记数组中,并从指定的索引处开始。 | 
| .gif) | Dispose | 执行与释放或重置非托管资源相关的应用程序定义的任务。 (继承自 IDisposable。) | 
| .gif) | EndInit | 基础结构。 | 
| .gif) | GetEnumerator | 返回一个循环访问集合的枚举数。 (继承自 IEnumerable。) | 
| .gif) | IndexOf | 确定指定的智能标记在 SmartTagCollection 中的索引。 | 
| .gif) | Insert | 将智能标记插入 SmartTagCollection 的指定索引处。 | 
| .gif) | Remove | 从 SmartTagCollection 中移除智能标记。 | 
页首
备注
在创建智能标记时,将 SmartTagBase 对象添加到 Workbook.VstoSmartTags 或 Document.VstoSmartTags 属性。 这些属性具有类型 SmartTagCollection。
有关 Office 解决方案中的智能标记的更多信息,请参见 智能标记概述。
提示
此接口由 Visual Studio Tools for Office 运行时实现。不应在代码中实现此接口。有关更多信息,请参见 Visual Studio Tools for Office Runtime 概述。
用法
此类型仅应在用于 Excel 2007 和 Word 2007 的项目中使用。 在 Word 2010 和 Excel 2010 中弃用了智能标记。 有关更多信息,请参见 智能标记概述。
本文档介绍面向 .NET Framework 4 的 Office 项目中所用此类型的版本。在面向 .NET Framework 3.5 的项目中,此类型可能具有不同的成员,因此本文档为此类型提供的代码示例可能并不适用。有关在面向 .NET Framework 3.5 的项目中使用此类型的文档,请参见 Visual Studio 2008 文档中以下参考部分:https://go.microsoft.com/fwlink/?LinkId=160658。
示例
下面的代码使用 Add 方法将 Microsoft.Office.Tools.Excel.SmartTag 添加到 Workbook.VstoSmartTags 属性公开的智能标记的集合中。 此代码示例摘自为 Microsoft.Office.Tools.Excel.Action 提供的一个更大的示例。
此示例针对的是文档级自定义项。
WithEvents displayAddress As Microsoft.Office.Tools.Excel.Action
Private Sub AddSmartTag()
    ' Create the smart tag for .NET Framework 4 projects.
    Dim smartTagDemo As Microsoft.Office.Tools.Excel.SmartTag = _
        Globals.Factory.CreateSmartTag(
        "www.microsoft.com/Demo#DemoSmartTag",
        "Demonstration Smart Tag")
    ' For .NET Framework 3.5 projects, use the following code to create the smart tag.
    ' Dim smartTagDemo As New  _
    '    Microsoft.Office.Tools.Excel.SmartTag( _
    '    "www.microsoft.com/Demo#DemoSmartTag", _
    '    "Demonstration Smart Tag")
    ' Specify a term and an expression to recognize.
    smartTagDemo.Terms.Add("sale")
    smartTagDemo.Expressions.Add( _
        New System.Text.RegularExpressions.Regex( _
        "[I|i]ssue\s\d{5,6}"))
    ' Create the action for .NET Framework 4 projects.
    displayAddress = Globals.Factory.CreateAction("To be replaced")
    ' For .NET Framework 3.5 projects, use the following code to create the action.
    ' displayAddress = New Microsoft.Office.Tools.Excel.Action("To be replaced")
    ' Add the action to the smart tag.
    smartTagDemo.Actions = New Microsoft.Office.Tools.Excel.Action() { _
            displayAddress}
    ' Add the smart tag.
    Me.VstoSmartTags.Add(smartTagDemo)
End Sub
private Microsoft.Office.Tools.Excel.Action displayAddress;
private void AddSmartTag()
{
    // Create the smart tag for .NET Framework 4 projects.
    Microsoft.Office.Tools.Excel.SmartTag smartTagDemo =
        Globals.Factory.CreateSmartTag(
            "www.microsoft.com/Demo#DemoSmartTag",
            "Demonstration Smart Tag");
    // For .NET Framework 3.5 projects, use the following code to create the smart tag.
    // Microsoft.Office.Tools.Excel.SmartTag smartTagDemo =
        // new Microsoft.Office.Tools.Excel.SmartTag(
        //     "www.microsoft.com/Demo#DemoSmartTag",
        //     "Demonstration Smart Tag");
    // Specify a term and an expression to recognize.
    smartTagDemo.Terms.Add("sale");
    smartTagDemo.Expressions.Add(
        new System.Text.RegularExpressions.Regex(
        @"[I|i]ssue\s\d{5,6}"));
    // Create the action for .NET Framework 4 projects.
    displayAddress = Globals.Factory.CreateAction("To be replaced");
    // For .NET Framework 3.5 projects, use the following code to create the action.
    // displayAddress = new Microsoft.Office.Tools.Excel.Action("To be replaced");
    // Add the action to the smart tag.
    smartTagDemo.Actions = new Microsoft.Office.Tools.Excel.Action[] { 
        displayAddress };
    // Add the smart tag.
    this.VstoSmartTags.Add(smartTagDemo);
    displayAddress.BeforeCaptionShow += new 
        Microsoft.Office.Tools.Excel.BeforeCaptionShowEventHandler(
        DisplayAddress_BeforeCaptionShow);
    displayAddress.Click += new 
        Microsoft.Office.Tools.Excel.ActionClickEventHandler(
        DisplayAddress_Click);
}