다음을 통해 공유


Factory.CreateSmartTag 메서드

워크시트의 스마트 태그를 나타내는 SmartTag 개체를 만듭니다.

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

구문

‘선언
Function CreateSmartTag ( _
    smartTagType As String, _
    caption As String, _
    extension As ISmartTagExtension _
) As SmartTag
SmartTag CreateSmartTag(
    string smartTagType,
    string caption,
    ISmartTagExtension extension
)

매개 변수

  • smartTagType
    형식: System.String
    파운드 기호(#)로 구분되는 네임스페이스 URI 및 태그 형식 이름으로 구성된 스마트 태그의 고유 식별자입니다.
  • caption
    형식: System.String
    스마트 태그 이름이며 스마트 태그 메뉴에 표시됩니다.

반환 값

형식: Microsoft.Office.Tools.Excel.SmartTag
새 스마트 태그입니다.

예외

예외 상황
ArgumentException

smartTagType 또는 caption이 nullNull 참조(Visual Basic의 경우 Nothing)이거나 비어 있거나 smartTagType이 잘못된 경우

설명

smartTagType parameter is http://smarttags.contoso.com#TagName에 대한 유효한 문자열의 예. 제대로 구성된 스마트 태그 형식 문자열에는 공백이 없으며 문자(a-z, A-Z), 밑줄(_) 또는 콜론(:)으로 시작됩니다.

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

예제

다음 코드 예제에서는 Excel 통합 문서 프로젝트에서 스마트 태그와 작업을 만드는 방법을 보여 줍니다. 이 예제를 사용하려면 ThisWorkbook 클래스에서 코드를 실행합니다.

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

Private Sub AddSmartTag()

    ' Create the smart tag for .NET Framework 4 projects.
    Dim smartTagDemo As Microsoft.Office.Tools.Excel.SmartTag = _
        Globals.Factory.CreateSmartTag(
        "www.microsoft.com/Demo#DemoSmartTag",
        "Demonstration Smart Tag")

    ' For .NET Framework 3.5 projects, use the following code to create the smart tag.
    ' 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 for .NET Framework 4 projects.
    displayAddress = Globals.Factory.CreateAction("To be replaced")

    ' For .NET Framework 3.5 projects, use the following code to 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 Microsoft.Office.Tools.Excel.Action displayAddress;

private void AddSmartTag()
{
    // Create the smart tag for .NET Framework 4 projects.
    Microsoft.Office.Tools.Excel.SmartTag smartTagDemo =
        Globals.Factory.CreateSmartTag(
            "www.microsoft.com/Demo#DemoSmartTag",
            "Demonstration Smart Tag");

    // For .NET Framework 3.5 projects, use the following code to create the smart tag.
    // 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 for .NET Framework 4 projects.
    displayAddress = Globals.Factory.CreateAction("To be replaced");

    // For .NET Framework 3.5 projects, use the following code to 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);
}

.NET Framework 보안

  • 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.

참고 항목

참조

Factory 인터페이스

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