Classe Action (System 2007)
Aggiornamento: novembre 2007
Rappresenta un'azione smart tag di Visual Studio Tools per Office in una cartella di lavoro di Microsoft Office Excel.
Spazio dei nomi: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)
Sintassi
<PermissionSetAttribute(SecurityAction.Demand, Name := "FullTrust")> _
Public Class Action _
Inherits ActionBase
Dim instance As Action
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public class Action : ActionBase
Note
Le azioni sono le opzioni rese disponibili nel menu di scelta rapida Smart tag quando viene riconosciuto uno smart tag di un certo tipo. Un'azione possibile può essere, ad esempio, "Aggiungi nome alla cartella Contatti" per una stringa di tipo Nome utente. Per ulteriori informazioni sugli smart tag in Visual Studio Tools per Office, vedere Architettura degli smart tag.
Esempi
Nell'esempio di codice riportato di seguito viene illustrato come creare un oggetto SmartTag con un oggetto Action per il riconoscimento del termine "sale" e dell'espressione regolare "[I|i]ssue\s\d{5,6}". L'azione modifica la didascalia di menu dell'azione in fase di esecuzione e visualizza l'indirizzo del testo riconosciuto. Per verificare l'esempio digitare la parola "sale" in una cella e la stringa "issue 12345" in un'altra, quindi provare l'azione smart tag.
Questo esempio è valido per una personalizzazione a livello di documento.
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);
}
Gerarchia di ereditarietà
System.Object
Microsoft.Office.Tools.ActionBase
Microsoft.Office.Tools.Excel.Action
Codice thread safe
Qualsiasi membro static (Shared in Visual Basic) pubblico di questo tipo è thread-safe. I membri di istanza non sono garantiti come thread-safe.
Vedere anche
Riferimenti
Spazio dei nomi Microsoft.Office.Tools.Excel
Altre risorse
Procedura: aggiungere smart tag a cartelle di lavoro di Excel
Procedura: creare smart tag con sistemi di riconoscimento personalizzati in Excel