방법: 문서에 관리 코드 확장 연결(2007 시스템)

업데이트: 2007년 11월

적용 대상

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

프로젝트 형식

  • 문서 수준 프로젝트

Microsoft Office 버전

  • 2007 Microsoft Office system

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

Visual Studio Tools for Office 사용자 지정을 기존의 Microsoft Office Word 2007 문서 또는 Microsoft Office Excel 2007 통합 문서에 연결할 수 있습니다. 문서나 통합 문서는 Visual Studio Tools for Office에서 지원하는 파일 형식일 수 있습니다. 자세한 내용은 문서 수준 사용자 지정 아키텍처를 참조하십시오.

참고:

코드에서 컨트롤을 지정된 문서에 없는 것으로 예상하는 경우 사용자 지정이 로드되지 않습니다.

Visual Studio Tools for Office 사용자 지정을 Word 또는 Excel 문서에 연결하려면 ServerDocument 클래스의 AddCustomization 메서드를 사용합니다. ServerDocument 클래스는 Microsoft Office가 설치되어 있지 않은 컴퓨터에서 실행하도록 디자인되었으므로 콘솔 또는 Windows Forms 응용 프로그램과 같이 Visual Studio Tools for Office 프로젝트를 기반으로 하지 않는 솔루션에서 이 메서드를 사용할 수 있습니다.

문서에 관리 코드 확장을 연결하려면

  1. 콘솔 응용 프로그램이나 Windows Forms 프로젝트와 같이 Word 또는 Excel을 시작하지 않는 새 프로젝트를 만듭니다.

  2. 새 프로젝트에서 다음 어셈블리에 대한 참조를 추가합니다.

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll

    • Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll

  3. 코드 파일의 맨 위에 다음 Imports or using 문을 추가합니다.

    Imports Microsoft.VisualStudio.Tools.Applications
    Imports Microsoft.VisualStudio.Tools.Applications.Runtime
    
    using Microsoft.VisualStudio.Tools.Applications;
    using Microsoft.VisualStudio.Tools.Applications.Runtime;
    
  4. 정적 AddCustomization 메서드를 호출합니다.

    다음 코드 예제에서는 AddCustomization 오버로드를 사용합니다. 이 오버로드에서는 문서의 전체 경로 및 문서에 연결할 사용자 지정에 대한 배포 매니페스트의 위치를 지정하는 Uri를 사용합니다. 이 예제에서는 WordDocument1.docx라는 Word 문서가 데시크톱에 있고 배포 매니페스트가 데스크톱에 있는 Publish라는 폴더에 있다고 가정합니다.

    Dim documentPath As String = System.Environment.GetFolderPath( _
         Environment.SpecialFolder.Desktop) + "\WordDocument1.docx"
    Dim runtimeVersion As Integer = 0
    
    Try
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath)
    
        ' Make sure that this document does not yet have any Visual Studio Tools 
        ' for Office customizations.
        If runtimeVersion = 0 Then
            Dim deployManifestPath As String = System.Environment.GetFolderPath( _
                Environment.SpecialFolder.Desktop) & "\Publish\WordDocument1.vsto"
            Dim deploymentManifestUri As New Uri(deployManifestPath)
            ServerDocument.AddCustomization(documentPath, deploymentManifestUri)
            System.Windows.Forms.MessageBox.Show("The document was successfully customized.")
        Else
            System.Windows.Forms.MessageBox.Show("The document is already customized.")
        End If
    Catch ex As FileNotFoundException
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.")
    Catch ex As DocumentNotCustomizedException
        System.Windows.Forms.MessageBox.Show("The document could not be customized." & _
            vbLf & ex.Message)
    End Try
    
    string documentPath = System.Environment.GetFolderPath(
        Environment.SpecialFolder.Desktop) + @"\WordDocument1.docx";
    int runtimeVersion = 0;
    
    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
    
        // Make sure that this document does not yet have any Visual Studio Tools 
        // for Office customizations.
        if (runtimeVersion == 0)
        {
            string deployManifestPath = System.Environment.GetFolderPath(
                Environment.SpecialFolder.Desktop) + @"\Publish\WordDocument1.vsto";
    
            Uri deploymentManifestUri = new Uri(deployManifestPath);
            ServerDocument.AddCustomization(documentPath, deploymentManifestUri);
            System.Windows.Forms.MessageBox.Show("The document was successfully customized.");
        }
        else
        {
            System.Windows.Forms.MessageBox.Show("The document is already customized.");
        }
    }
    catch (FileNotFoundException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.");
    }
    catch (DocumentNotCustomizedException ex)
    {
        System.Windows.Forms.MessageBox.Show("The document could not be customized.\n" +
            ex.Message);
    }
    

참고 항목

작업

방법: ServerDocument 클래스의 두 버전을 모두 사용하는 코드 작성

방법: 문서에서 관리 코드 확장 제거(2007 시스템)

방법: 문서에서 관리 코드 확장 제거(2003 시스템)

방법: 문서에 관리 코드 확장 연결(2003 시스템)

개념

ServerDocument 클래스를 사용하여 서버의 문서 관리

Office 솔루션의 응용 프로그램 및 배포 매니페스트