次の方法で共有


Action インターフェイス

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 システムのプロジェクト専用です。スマート タグは Office 2010 では使用されていません。
. (ActionBase から継承されます。)

このページのトップへ

イベント

  名前 説明
パブリック イベント BeforeCaptionShow ユーザーがスマート タグ アイコンをクリックしてからスマート タグ メニューが表示されるまでの間に発生します。 この型またはメンバーは 2007 Microsoft Office システムのプロジェクト専用です。スマート タグは Office 2010 では使用されていません。
.
パブリック イベント Click スマート タグ メニューでアクションをクリックした場合に発生します。 この型またはメンバーは 2007 Microsoft Office システムのプロジェクト専用です。スマート タグは Office 2010 では使用されていません。
.

このページのトップへ

解説

アクションとは、特定の種類のスマート タグが認識された場合に、スマート タグ ショートカット メニューで使用できる選択肢のことです。 アクションを作成するには、Action のオブジェクトの作成に Globals.Factory.CreateAction のメソッドを使用します。

注意

これは、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 を参照してください。

"sale" という用語および "[I|i]ssue\s\d{5,6}" という正規表現を認識する Action が設定された SmartTag を作成するコード例を次に示します。 このアクションは、実行時にこのアクションのメニュー キャプションを変更し、認識したテキストのアドレスを表示します。 この例をテストするには、1 つのセルに「sale」、もう 1 つのセルに「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);
}

参照

関連項目

Microsoft.Office.Tools.Excel 名前空間

SmartTag