表示使用 Visual Studio 中的 Office 开发工具自定义的 Excel 工作簿中的智能标记操作。
命名空间: Microsoft.Office.Tools.Excel
程序集: Microsoft.Office.Tools.Excel(在 Microsoft.Office.Tools.Excel.dll 中)
语法
声明
<GuidAttribute("37e25b46-6941-4833-9b08-e692cf461982")> _
Public Interface Action _
Inherits ActionBase
[GuidAttribute("37e25b46-6941-4833-9b08-e692cf461982")]
public interface Action : ActionBase
Action 类型公开以下成员。
属性
名称 | 说明 | |
---|---|---|
![]() |
Caption | 获取或设置操作的名称,如智能标记菜单中所示。 此类型或成员只适合在 2007 Microsoft Office system 项目中使用。Office 2010 中已弃用智能标记。 . (继承自 ActionBase。) |
页首
事件
名称 | 说明 | |
---|---|---|
![]() |
BeforeCaptionShow | 在用户单击智能标记图标之后、智能标记菜单显示之前发生。 此类型或成员只适合在 2007 Microsoft Office system 项目中使用。Office 2010 中已弃用智能标记。 . |
![]() |
Click | 在智能标记菜单中的操作被单击时发生。 此类型或成员只适合在 2007 Microsoft Office system 项目中使用。Office 2010 中已弃用智能标记。 . |
页首
备注
在识别到某种类型的智能标记时,智能标记的快捷菜单上会出现可供选择的操作。若要创建事件,请使用 Globals.Factory.CreateAction 方法创建 Action 对象。
![]() |
---|
此接口由 Visual Studio Tools for Office Runtime 实现。不应在代码中实现此接口。有关更多信息,请参见 Visual Studio Tools for Office Runtime 概述。 |
用法
此类型的设计目的是仅用在 Excel 2007 的项目中。智能标记是弃用 Excel 2010。
本文档介绍面向 .NET Framework 4 和 .NET Framework 4.5 的 Office 项目中所用此类型的版本。在面向 .NET Framework 3.5 的项目中,此类型可能具有不同的成员,因此本文档为此类型提供的代码示例可能并不适用。有关面向 .NET Framework 3.5 的项目中的此类型的文档,请参见 Visual Studio 2008 文档中的以下参考部分:https://go.microsoft.com/fwlink/?LinkId=160658。
示例
下面的代码示例创建一个 SmartTag,该智能标记有一个可识别术语“sale”和正则表达式“[I|i]ssue\s\d{5,6}”的 Action。该操作在运行时修改操作的菜单标题,并显示已识别的文本所在的地址。若要测试该示例,请在一个单元格中键入单词“sale”,在另一个单元格中键入字符串“issue 12345”,然后尝试执行该智能标记操作。
WithEvents displayAddress As Microsoft.Office.Tools.Excel.Action
Private Sub AddSmartTag()
Dim smartTagDemo As Microsoft.Office.Tools.Excel.SmartTag = _
Globals.Factory.CreateSmartTag(
"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}"))
displayAddress = Globals.Factory.CreateAction("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()
{
Microsoft.Office.Tools.Excel.SmartTag smartTagDemo =
Globals.Factory.CreateSmartTag(
"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}"));
displayAddress = Globals.Factory.CreateAction("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(Excel.XlReferenceStyle.xlA1);
System.Windows.Forms.MessageBox.Show("The recognized text '" + e.Text +
"' is at range " + smartTagAddress);
}