SmartTag Interface
Represents a smart tag in an Excel workbook that is customized by using the Office development tools in Visual Studio.
Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)
Syntax
'Declaration
<GuidAttribute("f210dc7f-21b5-475e-ae31-76a9b06b9835")> _
Public Interface SmartTag _
Inherits SmartTagBase
[GuidAttribute("f210dc7f-21b5-475e-ae31-76a9b06b9835")]
public interface SmartTag : SmartTagBase
The SmartTag type exposes the following members.
Properties
Name | Description | |
---|---|---|
Actions | Gets or sets an array of actions that are exposed by the smart tag. (Inherited from SmartTagBase.) | |
Caption | Gets the name of the smart tag. (Inherited from SmartTagBase.) | |
DefaultExtension | Gets the default extension for this SmartTag object. | |
Expressions | Gets the collection of regular expressions that the smart tag will recognize. (Inherited from SmartTagBase.) | |
Extension | Gets a custom extension for this SmartTag object. | |
SmartTagType | Gets a namespace that acts as a unique identifier for the smart tag. (Inherited from SmartTagBase.) | |
Terms | Gets the collection of string literals that the smart tag will recognize. (Inherited from SmartTagBase.) |
Top
Methods
Name | Description | |
---|---|---|
Remove | Removes a regular expression recognizer from the smart tag. (Inherited from SmartTagBase.) |
Top
Remarks
To create smart tag, use the Globals.Factory.CreateSmartTag method to create a SmartTag object. For information, see Smart Tags Architecture.
Note
This interface is implemented by the Visual Studio Tools for Office runtime. It is not intended to be implemented in your code. For more information, see Visual Studio Tools for Office Runtime Overview.
Usage
This type is intended to be used only in projects for Excel 2007. Smart tags are deprecated in Excel 2010. For more information, see Smart Tags Overview.
This documentation describes the version of this type that is used in Office projects that target the .NET Framework 4. In projects that target the .NET Framework 3.5, this type might have different members and the code examples provided for this type might not work. For documentation about this type in projects that target the .NET Framework 3.5, see the following reference section in the Visual Studio 2008 documentation: https://go.microsoft.com/fwlink/?LinkId=160658.
Examples
The following code example creates a SmartTag with an Action that recognizes the term "sale" and the regular expression "[I|i]ssue\s\d{5,6}". The action modifies the menu caption of the action at run time and displays the address of the text that was recognized. To test the example, type the word "sale" in one cell and the string "issue 12345" in another cell, and then try the smart tag 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 Sub DisplayAddress_BeforeCaptionShow(ByVal sender As Object, _
ByVal e As Microsoft.Office.Tools.Excel.ActionEventArgs) _
Handles DisplayAddress.BeforeCaptionShow
Dim clickedAction As Microsoft.Office.Tools.Excel.Action = _
TryCast(sender, Microsoft.Office.Tools.Excel.Action)
If clickedAction IsNot Nothing Then
clickedAction.Caption = "Display the address of " & e.Text
End If
End Sub
Private Sub DisplayAddress_Click(ByVal sender As Object, _
ByVal e As Microsoft.Office.Tools.Excel.ActionEventArgs) _
Handles DisplayAddress.Click
Dim smartTagAddress As String = e.Range.Address( _
ReferenceStyle:=Excel.XlReferenceStyle.xlA1)
MsgBox("The recognized text '" & e.Text & _
"' is at range " & smartTagAddress)
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);
}
void DisplayAddress_BeforeCaptionShow(object sender,
Microsoft.Office.Tools.Excel.ActionEventArgs e)
{
Microsoft.Office.Tools.Excel.Action clickedAction =
sender as Microsoft.Office.Tools.Excel.Action;
if (clickedAction != null)
{
clickedAction.Caption = "Display the address of " +
e.Text;
}
}
void DisplayAddress_Click(object sender,
Microsoft.Office.Tools.Excel.ActionEventArgs e)
{
string smartTagAddress = e.Range.get_Address(missing,
missing, Excel.XlReferenceStyle.xlA1, missing, missing);
System.Windows.Forms.MessageBox.Show("The recognized text '" + e.Text +
"' is at range " + smartTagAddress);
}
See Also
Reference
Microsoft.Office.Tools.Excel Namespace
Other Resources
How to: Add Smart Tags to Excel Workbooks
How to: Create Smart Tags With Custom Recognizers in Excel and .NET Framework 3.5