Action 类 (2007 system)
更新:2007 年 11 月
表示 Microsoft Office Excel 工作簿中的 Visual Studio Tools for Office 智能标记操作。
命名空间: Microsoft.Office.Tools.Excel
程序集: Microsoft.Office.Tools.Excel.v9.0(在 Microsoft.Office.Tools.Excel.v9.0.dll 中)
语法
声明
<PermissionSetAttribute(SecurityAction.Demand, Name := "FullTrust")> _
Public Class Action _
Inherits ActionBase
用法
Dim instance As Action
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public class Action : ActionBase
备注
在识别到某种类型的智能标记时,智能标记的快捷菜单上会出现可供选择的操作。对于类型为“Person's Name”(人名)的字符串,可能的操作示例就是“Add name to the Contacts folder”(向联系人文件夹添加姓名)。有关 Visual Studio Tools for Office 中的智能标记的更多信息,请参见智能标记的结构。
示例
下面的代码示例创建一个 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 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 Sub OpenMessageBox_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 =
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);
}
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);
}
继承层次结构
System.Object
Microsoft.Office.Tools.ActionBase
Microsoft.Office.Tools.Excel.Action
线程安全
此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。
另请参见
参考
Microsoft.Office.Tools.Excel 命名空间