创建一个 SmartTag 对象,该对象表示工作表中的一个智能标记。
命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel(在 Microsoft.Office.Tools.Excel.dll 中)
语法
声明
Function CreateSmartTag ( _
    smartTagType As String, _
    caption As String, _
    extension As ISmartTagExtension _
) As SmartTag
SmartTag CreateSmartTag(
    string smartTagType,
    string caption,
    ISmartTagExtension extension
)
参数
- smartTagType
 类型:System.String
 智能标记的唯一标识符,由命名空间 URI 和标记类型名组成,两部分之间用数字符号 (#) 分隔。
- caption
 类型:System.String
 智能标记菜单上显示的智能标记的名称。
- extension
 类型:Microsoft.Office.Tools.Excel.ISmartTagExtension
 可选。一个扩展对象,用于为智能标记定义自定义识别器。
返回值
类型:Microsoft.Office.Tools.Excel.SmartTag
新智能标记。
异常
| 异常 | 条件 | 
|---|---|
| ArgumentException | smartTagType 或 caption 为 nullnull 引用(在 Visual Basic 中为 Nothing) 或为空,或者 smartTagType 无效。 | 
备注
smartTagType 参数的有效字符串的示例:http://smarttags.contoso.com#TagName。 格式良好的智能标记类型字符串不包含空白,它以字母(a-z、A-Z)、下划线 (_) 或冒号 (:) 开头。
有关智能标记的更多信息,请参见 智能标记概述 和 智能标记的结构。
示例
下面的代码示例演示如何在 Excel 工作簿项目中创建智能标记和操作。 若要使用此示例,请在 ThisWorkbook 类中运行代码。
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);
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。