다음을 통해 공유


ISmartTagExtension 인터페이스

Visual Studio의 Office 개발 도구를 사용하여 사용자 지정한 Excel 워크시트의 스마트 태그 확장을 나타냅니다. 이 확장은 스마트 태그에 대한 사용자 지정 인식기를 정의합니다.

네임스페이스:  Microsoft.Office.Tools.Excel
어셈블리:  Microsoft.Office.Tools.Excel(Microsoft.Office.Tools.Excel.dll)

구문

‘선언
<GuidAttribute("baa275c5-e25c-49ba-87be-dbe0712f7eb1")> _
Public Interface ISmartTagExtension _
    Inherits IExtension
[GuidAttribute("baa275c5-e25c-49ba-87be-dbe0712f7eb1")]
public interface ISmartTagExtension : IExtension

ISmartTagExtension 형식에서는 다음과 같은 멤버를 노출합니다.

속성

  이름 설명
Public 속성 ExtensionBase IExtension에서 확장하고 있는 개체를 가져옵니다. (IExtension에서 상속됨)

위쪽

메서드

  이름 설명
Public 메서드 Recognize 셀의 텍스트에서 인식된 용어를 검색합니다.

위쪽

설명

Excel 워크시트에서 스마트 태그를 인식하는 방법을 제어하려면 ISmartTagExtension 인터페이스를 구현하십시오. 자세한 내용은 스마트 태그 아키텍처방법: Excel 및 .NET Framework 4에서 사용자 지정 인식기를 사용하여 스마트 태그 만들기을 참조하십시오.

용도

이 형식은 Excel 2007용 프로젝트에서만 사용할 수 있습니다. Excel 2010에서는 스마트 태그가 더 이상 사용되지 않습니다. 자세한 내용은 스마트 태그 개요을 참조하십시오.

예제

다음 코드 예제에서는 자신의 스마트 태그 인식기를 만들기 위해 ISmartTagExtension을 구현하는 방법을 보여 줍니다. 이 예제에서는 셀에 있는 각 스마트 태그 용어를 인식할 수 있게 Recognize 메서드를 구현합니다. 이 예제에서는 참조 추가 대화 상자의 .NET 탭에서 Microsoft.Office.Interop.SmartTag에 대한 참조를 추가한 것으로 가정합니다.

Imports System
Imports System.Windows.Forms
Imports Microsoft.Office.Interop.SmartTag
Imports Microsoft.Office.Tools.Excel

Public Class CustomSmartTag
    Implements ISmartTagExtension

    ' Declare the smart tag.
    Private smartTagDemo As Microsoft.Office.Tools.Excel.SmartTag

    ' Declare actions for this smart tag.
    WithEvents Action1 As Microsoft.Office.Tools.Excel.Action
    WithEvents Action2 As Microsoft.Office.Tools.Excel.Action

    Public Sub New()
        Me.smartTagDemo = Globals.Factory.CreateSmartTag(
            "https://www.contoso.com/Demo#DemoSmartTag", "Custom Smart Tag", Me)

        Action1 = Globals.Factory.CreateAction("Display property value")
        Action2 = Globals.Factory.CreateAction("Display smart tag details")

        smartTagDemo.Terms.AddRange(New String() {"sales", "organization"})
        smartTagDemo.Actions = New Microsoft.Office.Tools.Excel.Action() {Action1, Action2}
    End Sub

    Private Sub Recognize(ByVal text As String, 
        ByVal site As ISmartTagRecognizerSite, ByVal tokenList As ISmartTagTokenList, 
        ByVal context As SmartTagRecognizeContext) Implements ISmartTagExtension.Recognize

        ' Determine whether each smart tag term exists in the document text.
        Dim Term As String
        For Each Term In smartTagDemo.Terms

            ' Search the cell text for the first instance of 
            ' the current smart tag term.
            Dim index As Integer = context.CellText.IndexOf(Term, 0)

            If (index >= 0) Then

                ' Create a smart tag token and a property bag for the 
                ' recognized term.
                Dim propertyBag As ISmartTagProperties = site.GetNewPropertyBag()

                ' Write a new property value.
                Dim key As String = "Key1"
                propertyBag.Write(key, DateTime.Now)

                ' Attach the smart tag to the term in the document.
                context.PersistTag(propertyBag)

                ' This implementation only finds the first instance
                ' of a smart tag term in the cell. 
                Exit For
            End If
        Next
    End Sub

    ' This action displays the property value for the term.
    Private Sub Action1_Click(ByVal sender As Object,
        ByVal e As Microsoft.Office.Tools.Excel.ActionEventArgs) Handles Action1.Click

        Dim propertyBag As ISmartTagProperties = e.Properties
        Dim key As String = "Key1"
        MessageBox.Show("The corresponding value of " & key & " is: " &
            propertyBag.Read(key))
    End Sub

    ' This action displays smart tag details.
    Private Sub Action2_Click(ByVal sender As Object,
        ByVal e As Microsoft.Office.Tools.Excel.ActionEventArgs) Handles Action2.Click
        MessageBox.Show("The current smart tag caption is '" &
        smartTagDemo.Caption & "'. The current smart tag type is '" &
        smartTagDemo.SmartTagType & "'.")
    End Sub

    Public ReadOnly Property Base() As Microsoft.Office.Tools.Excel.SmartTag
        Get
            Return smartTagDemo
        End Get
    End Property

    Public ReadOnly Property ExtensionBase() As Object Implements ISmartTagExtension.ExtensionBase
        Get
            Return smartTagDemo
        End Get
    End Property
End Class
using System;
using System.Windows.Forms;
using Microsoft.Office.Interop.SmartTag;
using Microsoft.Office.Tools.Excel;

namespace Trin_ExcelDerivedSmartTags4
{
    class CustomSmartTag : ISmartTagExtension
    {
        // Declare the smart tag.
        Microsoft.Office.Tools.Excel.SmartTag smartTagDemo;

        // Declare actions for this smart tag.
        private Microsoft.Office.Tools.Excel.Action Action1;
        private Microsoft.Office.Tools.Excel.Action Action2;

        public CustomSmartTag()
        {
            this.smartTagDemo = Globals.Factory.CreateSmartTag(
                "https://www.contoso.com/Demo#DemoSmartTag", "Custom Smart Tag", this);

            Action1 = Globals.Factory.CreateAction("Display property value");
            Action2 = Globals.Factory.CreateAction("Display smart tag details");

            smartTagDemo.Terms.AddRange(new string[] { "sales", "organization" });
            smartTagDemo.Actions = new Microsoft.Office.Tools.Excel.Action[] { 
                Action1, Action2 };

            Action1.Click += new ActionClickEventHandler(Action1_Click);
            Action2.Click += new ActionClickEventHandler(Action2_Click);
        }

        void ISmartTagExtension.Recognize(string text, ISmartTagRecognizerSite site, 
            ISmartTagTokenList tokenList, SmartTagRecognizeContext context)
        {

            // Determine whether each smart tag term exists in the document text.
            foreach (string term in smartTagDemo.Terms)
            {
                // Search the cell text for the first instance of the current smart tag term.
                int index = context.CellText.IndexOf(term, 0);

                if (index >= 0)
                {
                    // Create a smart tag token and a property bag for the recognized term.
                    ISmartTagProperties propertyBag = site.GetNewPropertyBag();

                    // Write a new property value.                 
                    string key = "Key1";
                    propertyBag.Write(key, DateTime.Now.ToString());

                    // Attach the smart tag to the term in the document
                    context.PersistTag(propertyBag);

                    // This implementation only finds the first instance of a 
                    // smart tag term in the cell. 
                    break;
                }
            }
        }

        // This action displays the property value for the term.
        private void Action1_Click(object sender,
            Microsoft.Office.Tools.Excel.ActionEventArgs e)
        {
            ISmartTagProperties propertyBag = e.Properties;
            string key = "Key1";
            MessageBox.Show("The corresponding value of " + key +
                " is: " + propertyBag.get_Read(key));
        }

        // This action displays smart tag details.
        private void Action2_Click(object sender,
            Microsoft.Office.Tools.Excel.ActionEventArgs e)
        {
            MessageBox.Show("The current smart tag caption is '" +
                smartTagDemo.Caption + "'. The current smart tag type is '" +
                smartTagDemo.SmartTagType + "'.");
        }

        public Microsoft.Office.Tools.Excel.SmartTag Base
        {
            get { return smartTagDemo; }
        }

        public object ExtensionBase
        {
            get { return smartTagDemo; }
        }
    }

참고 항목

참조

Microsoft.Office.Tools.Excel 네임스페이스

기타 리소스

스마트 태그 아키텍처

방법: Excel 및 .NET Framework 4에서 사용자 지정 인식기를 사용하여 스마트 태그 만들기