다음을 통해 공유


방법: Excel 통합 문서에 스마트 태그 추가

업데이트: 2008년 7월

적용 대상

이 항목의 정보는 지정된 Visual Studio Tools for Office 프로젝트 및 Microsoft Office 버전에만 적용됩니다.

문서 수준 프로젝트

  • Excel 2003

  • Excel 2007

응용 프로그램 수준 프로젝트

  • Excel 2007

자세한 내용은 응용 프로그램 및 프로젝트 형식에 따라 사용 가능한 기능을 참조하십시오.

Microsoft Office Excel 통합 문서에 스마트 태그를 추가하여 텍스트를 인식하고 인식된 용어와 관련된 동작에 사용자가 액세스하도록 할 수 있습니다. 스마트 태그를 만들고 구성하기 위해 작성하는 코드는 문서 수준 프로젝트의 경우와 응용 프로그램 수준 프로젝트의 경우에 모두 동일하지만 스마트 태그를 통합 문서와 연결하는 방식에는 몇 가지 차이점이 있습니다. 또한 스마트 태그의 범위도 문서 수준 프로젝트와 응용 프로그램 수준 프로젝트에서 서로 다릅니다.

이 항목에서는 다음 작업에 대해 설명합니다.

  • 문서 수준 사용자 지정에서 스마트 태그 추가

  • 응용 프로그램 수준 추가 기능에서 스마트 태그 추가

스마트 태그를 실행하려면 최종 사용자의 Word 또는 Excel에서 스마트 태그를 사용하도록 설정되어 있어야 합니다. 자세한 내용은 방법: Word 및 Excel에서 스마트 태그 사용을 참조하십시오.

문서 수준 사용자 지정에서 스마트 태그 추가

문서 수준 사용자 지정을 사용하여 스마트 태그를 추가할 경우 스마트 태그는 해당 사용자 지정과 연결된 통합 문서에서만 인식됩니다.

문서 수준 사용자 지정을 사용하여 스마트 태그를 추가하려면

  1. SmartTag 개체를 만들고 스마트 태그의 동작을 정의하도록 구성합니다.

    • 인식할 텍스트를 지정하려면 Terms 또는 Expressions 속성을 사용합니다.

    • 사용자가 스마트 태그에 대해 클릭하여 실행할 수 있는 작업을 정의하려면 Actions 속성에 Action 개체를 하나 이상 추가합니다.

    자세한 내용은 스마트 태그 아키텍처를 참조하십시오.

  2. ThisWorkbook 클래스의 VstoSmartTags 속성에 SmartTag를 추가합니다.

다음 코드 예제에서는 sale이라는 단어와 [I|i]ssue\s\d{5,6} 정규식을 인식하는 스마트 태그를 만듭니다. 사용자가 sale 또는 정규식에 일치하는 문자열(예: issue 12345)을 입력한 다음 스마트 태그를 클릭하면 인식된 텍스트의 셀 위치가 표시됩니다. 이 코드를 실행하려면 ThisWorkbook 클래스에 코드를 추가하고 ThisWorkbook_Startup 이벤트 처리기에서 AddSmartTag 메서드를 호출합니다.

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);
}

응용 프로그램 수준 추가 기능에서 스마트 태그 추가

SP1부터는 응용 프로그램 수준 추가 기능을 사용하여 스마트 태그를 추가할 수 있습니다. 스마트 태그가 특정 통합 문서에서만 작동하도록 할지 열려 있는 모든 통합 문서에서 작동하도록 할지를 지정할 수 있습니다. 열려 있는 모든 통합 문서에서 실행되는 스마트 태그는 응용 프로그램 수준 스마트 태그라고 합니다.

특정 통합 문서에 스마트 태그를 추가하려면

  1. SmartTag 개체를 만들고 스마트 태그의 동작을 정의하도록 구성합니다.

    • 인식할 텍스트를 지정하려면 Terms 또는 Expressions 속성을 사용합니다.

    • 사용자가 스마트 태그에 대해 클릭하여 실행할 수 있는 작업을 정의하려면 Actions 속성에 Action 개체를 하나 이상 추가합니다.

    자세한 내용은 스마트 태그 아키텍처를 참조하십시오.

  2. GetVstoObject 메서드를 사용하여 스마트 태그를 호스팅할 통합 문서에 대한 Workbook 호스트 항목을 만듭니다. 호스트 항목을 만드는 방법에 대한 자세한 내용은 런타임에 응용 프로그램 수준 추가 기능의 Word 문서 및 Excel 통합 문서 확장을를 참조하십시오.

    참고:

    SP1을 설치하기 전에 만든 프로젝트를 사용하는 경우 GetVstoObject 메서드를 사용하려면 먼저 프로젝트를 수정해야 합니다. 자세한 내용은 런타임에 응용 프로그램 수준 추가 기능의 Word 문서 및 Excel 통합 문서 확장을 참조하십시오.

  3. WorkbookVstoSmartTags 속성에 SmartTag를 추가합니다.

다음 코드 예제에서는 sale이라는 단어와 [I|i]ssue\s\d{5,6} 정규식을 인식하는 스마트 태그를 만듭니다. 사용자가 sale 또는 정규식에 일치하는 문자열(예: issue 12345)을 입력한 다음 스마트 태그를 클릭하면 인식된 텍스트의 셀 위치가 표시됩니다. 이 코드를 실행하려면 ThisAddIn 클래스에 코드를 추가하고 ThisAddIn_Startup 이벤트 처리기에서 AddSmartTagToActiveWorkbook 메서드를 호출합니다.

WithEvents displayAddress As Microsoft.Office.Tools.Excel.Action

Private Sub AddSmartTagToActiveWorkbook()
    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 to the active workbook.
    Dim vstoWorkbook As Microsoft.Office.Tools.Excel.Workbook = _
        Me.Application.ActiveWorkbook.GetVstoObject()
    vstoWorkbook.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 AddSmartTagToActiveWorkbook()
{
    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 to the active workbook.
    Microsoft.Office.Tools.Excel.Workbook vstoWorkbook =
        this.Application.ActiveWorkbook.GetVstoObject();
    vstoWorkbook.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);
}

열려 있는 모든 통합 문서에서 작동하는 스마트 태그를 추가하려면

  1. SmartTag 개체를 만들고 스마트 태그의 동작을 정의하도록 구성합니다.

    • 인식할 텍스트를 지정하려면 Terms 또는 Expressions 속성을 사용합니다.

    • 사용자가 스마트 태그에 대해 클릭하여 실행할 수 있는 작업을 정의하려면 Actions 속성에 Action 개체를 하나 이상 추가합니다.

    자세한 내용은 스마트 태그 아키텍처를 참조하십시오.

  2. ThisAddIn 클래스의 VstoSmartTags 속성에 SmartTag를 추가합니다.

    참고:

    SP1을 설치하기 전에 만든 프로젝트를 사용하는 경우 VstoSmartTags 속성을 생성하려면 프로젝트를 수정해야 합니다. 자세한 내용은 방법: 응용 프로그램 수준 스마트 태그를 SP1 이전에 만든 프로젝트에 추가을를 참조하십시오.

다음 코드 예제에서는 sale이라는 단어와 [I|i]ssue\s\d{5,6} 정규식을 인식하는 스마트 태그를 만듭니다. 사용자가 sale 또는 정규식에 일치하는 문자열(예: issue 12345)을 입력한 다음 스마트 태그를 클릭하면 인식된 텍스트의 셀 위치가 표시됩니다. 이 코드를 실행하려면 ThisAddIn 클래스에 코드를 추가하고 ThisAddIn_Startup 이벤트 처리기에서 AddSmartTag 메서드를 호출합니다.

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);
}

보안

Excel에서 스마트 태그를 사용하도록 설정해야 합니다. 기본적으로 Excel에서는 스마트 태그를 사용하도록 설정되어 있지 않습니다. 자세한 내용은 방법: Word 및 Excel에서 스마트 태그 사용을 참조하십시오.

참고 항목

작업

방법: Word 및 Excel에서 스마트 태그 사용

방법: Word 문서에 스마트 태그 추가

방법: 응용 프로그램 수준 스마트 태그를 SP1 이전에 만든 프로젝트에 추가

방법: Word에서 사용자 지정 인식자로 스마트 태그 만들기

방법: Excel에서 사용자 지정 인식자로 스마트 태그 만들기

연습: 문서 수준 사용자 지정을 사용하여 스마트 태그 만들기

연습: 응용 프로그램 수준 추가 기능을 사용하여 스마트 태그 만들기

개념

스마트 태그 개요

스마트 태그 아키텍처

스마트 태그 아키텍처

Office 솔루션 개발

변경 기록

날짜

변경 내용

원인

2008년 7월

응용 프로그램 수준 추가 기능에 대한 절차가 새로 추가되었습니다.

SP1 기능 변경