SmartTagCollection.Add 方法 (2007 system)
更新:2007 年 11 月
将智能标记添加到 SmartTagCollection 的末尾。
命名空间: Microsoft.Office.Tools
程序集: Microsoft.Office.Tools.Common.v9.0(在 Microsoft.Office.Tools.Common.v9.0.dll 中)
语法
声明
Public Function Add ( _
value As SmartTagBase _
) As Integer
用法
Dim instance As SmartTagCollection
Dim value As SmartTagBase
Dim returnValue As Integer
returnValue = instance.Add(value)
public int Add(
SmartTagBase value
)
参数
value
类型:Microsoft.Office.Tools.SmartTagBase要添加的智能标记实例。
返回值
类型:System.Int32
新智能标记在 SmartTagCollection 中的索引。
示例
下面的代码使用 Add 方法将 Microsoft.Office.Tools.Excel.SmartTag 添加到 Workbook.VstoSmartTags 属性公开的智能标记的集合中。此代码示例摘自为 Microsoft.Office.Tools.Excel.Action 类提供的一个更大示例。
此示例针对的是文档级自定义项。
WithEvents displayAddress As Microsoft.Office.Tools.Excel.Action
Private Sub AddSmartTag()
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.
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()
{
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.
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);
}
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。