ApplicationFactory.CreateSmartTag Method
Creates a SmartTag object that represents a smart tag on a worksheet.
Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)
Syntax
'Declaration
Function CreateSmartTag ( _
smartTagType As String, _
caption As String, _
extension As ISmartTagExtension _
) As SmartTag
SmartTag CreateSmartTag(
string smartTagType,
string caption,
ISmartTagExtension extension
)
Parameters
- smartTagType
Type: System.String
A unique identifier for the smart tag, composed of a namespace URI and a tag type name separated by a number sign (#).
- caption
Type: System.String
The name of the smart tag, which is displayed on the smart tag menu.
- extension
Type: Microsoft.Office.Tools.Excel.ISmartTagExtension
Optional. An extension object that defines a custom recognizer for the smart tag.
Return Value
Type: Microsoft.Office.Tools.Excel.SmartTag
The new smart tag.
Exceptions
Exception | Condition |
---|---|
ArgumentException | smartTagType or caption is either nulla null reference (Nothing in Visual Basic) or empty, or smartTagType is not valid. |
Remarks
An example of a valid string for the smartTagType parameter is http://smarttags.contoso.com#TagName. A well-formed smart tag type string does not contain white space, and it starts with a letter (a-z, A-Z), an underscore (_), or a colon (:).
For more information about smart tags, see Smart Tags Overview and Smart Tags Architecture.
Examples
The following code example demonstrates how to create a smart tag and an action in an Excel add-in project. To use this example, run the code from the ThisAddIn class.
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 Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.