如何:在 Visual Studio 中创建 Office 项目How to: Create Office projects in Visual Studio

可以使用Visual StudioVisual Studio创建 VSTO 外接程序和文档级自定义 Microsoft Office 应用程序。You can use Visual StudioVisual Studio to create VSTO Add-in and document-level customizations for Microsoft Office applications. 有关这些类型的项目的详细信息,请参阅Office 解决方案开发概述(VSTO)For more information about these types of projects, see Office solutions development overview (VSTO).

适用于: 本主题中的信息适用于文档-级别项目和 VSTO 添加-在项目中。Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects. 请参阅按 Office 应用程序和项目类型提供的功能See Features available by Office application and project type.

Note

以下说明中的某些 Visual Studio 用户界面元素在计算机上出现的名称或位置可能会不同。Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. 这些元素取决于你所使用的 Visual Studio 版本和你所使用的设置。The Visual Studio edition that you have and the settings that you use determine these elements. 有关详细信息,请参阅个性化设置 IDEFor more information, see Personalize the IDE.

创建 VSTO 外接程序项目To create a VSTO Add-in project

  1. 在“文件”菜单上,选择“新建” > “项目”。On the File menu, choose New > Project. 如果你的集成的开发环境 (IDE) 设置为使用Visual BasicVisual Basic开发设置,然后在文件菜单中,选择新建 > 项目If your integrated development environment (IDE) is set to use Visual BasicVisual Basic development settings, on the File menu, choose New > Project.

    此时将出现“新建项目”对话框。The New Project dialog box appears.

    Note

    默认情况下,Office 项目均面向 .NET Framework 4.5.NET Framework 4.5Office projects target the .NET Framework 4.5.NET Framework 4.5 by default. 有关详细信息,请参阅.NET Framework 客户端配置文件For more information, see .NET Framework client profile.

  2. 在所需的语言节点下的模板窗格中,展开Office/SharePointIn the templates pane, under the node for the language you want to use, expand Office/SharePoint.

  3. 选择Office 加载项节点。Choose the Office Add-ins node.

  4. 在项目模板列表中,选择 VSTO 外接程序项目模板。In the list of project templates, select a VSTO Add-in project template. 有关可用 VSTO 外接程序项目模板的列表,请参阅Office 项目模板概述For a list of available VSTO Add-in project templates, see Office project templates overview.

    Note

    如果项目模板不可见时选择Office 加载项节点,请确保 .NET Framework 4或更高版本选择对话框顶部组合框中。If project templates are not visible when you select the Office Add-ins node, make sure that .NET Framework 4 or later is selected in the combo box at the top of the dialog box. Office 项目模板对于 .NET Framework 的两个版本均为可见。Office project templates are visible for both versions of the .NET Framework.

  5. 在中名称框中,键入项目的名称。In the Name box, type a name for the project. 默认情况下,项目名称也可用作解决方案名称。By default, the project name is also used as the solution name.

  6. 在中位置框中,输入你想要创建项目的路径。In the Location box, enter the path where you want to create the project. 你可以使用绝对路径和通用命名约定 (UNC) 路径。You can use absolute and universal naming convention (UNC) paths. 不允许使用 HTTP、FTP 或其他协议的路径。Do not use HTTP, FTP, or other protocol paths.

    位置具有以下格式:Locations have the following formats:

    • [drive]:[drive]:

    • \\Server\Share\\Server\Share

      不允许在该位置中使用以下字符:Do not use these characters in the location:

    • 星号 (*)Asterisk (*)

    • 竖线 (|)Vertical bar (|)

    • 冒号 (:)(接在驱动器号之后的情况除外)Colon (:) (Except following the drive letter.)

    • 双引号 (")(包含空格的路径不需要引号。)Double quotation mark (") (Paths that contain spaces do not need quotation marks.)

    • 小于 (<)Less than (<)

    • 大于 (>)Greater than (>)

    • 问号 (?)Question mark (?)

    • 百分号 (%)Percent sign (%)

  7. 选择“确定” 按钮。Choose the OK button.

    Note

    创建外接程序项目时,要始终对其进行保存。Add-in projects are always saved when they are created. 不能将其创建为临时项目。They cannot be created as temporary projects. 有关临时项目的详细信息,请参阅临时项目For more information about temporary projects, see Temporary projects.

若要创建文档级自定义项目To create a document-level customization project

  1. 在“文件”菜单上,选择“新建” > “项目”。On the File menu, choose New > Project. 如果您的 IDE 设置上使用 Visual Basic 开发设置文件菜单中,选择新建 > 项目If your IDE is set to use Visual Basic development settings, on the File menu, choose New > Project.

    此时将出现“新建项目”对话框。The New Project dialog box appears.

  2. 在所需的语言节点下的模板窗格中,展开Office/SharePointIn the templates pane, under the node for the language you want to use, expand Office/SharePoint.

  3. 选择“Office 外接程序” 节点。Select the Office Add-ins node.

  4. 在项目模板列表中,选择一个文档级项目模板。In the list of project templates, select a document-level project template. 有关可用文档级项目模板的列表,请参阅Office 项目模板概述For a list of available document-level project templates, see Office project templates overview.

    Note

    如果项目模板不可见时选择Office 加载项节点,请确保 .NET Framework 4或更高版本。If project templates are not visible when you select the Office Add-ins node, make sure that .NET Framework 4 or later is selected.

  5. 在中名称框中,键入项目的名称。In the Name box, type a name for the project. 默认情况下,此名称还用于文档。By default, this name is also used for the document. 如果 IDE 设置为使用 Visual C# 开发设置或常规开发设置,请输入位置和解决方案名称。If your IDE is set to use Visual C# development settings or General development settings, also enter a location and solution name.

    Note

    不能在项目位置路径或项目名称中使用代理项字符。You cannot use surrogate characters in the path of the project location or in the project name. 此外,如果计划部署脱机使用的解决方案,则该项目名称中的字符必须符合 HTTP 协议规范。Also, if you plan to deploy the solution for use offline, the characters in the project name must fit the HTTP protocol specifications.

  6. 选择“确定” 按钮。Choose the OK button.

    将打开“Visual Studio Tools for Office 项目向导” 。The Visual Studio Tools for Office Project Wizard opens.

  7. 选择创建一个新文档如果你想要创建新文档的解决方案,或选择复制现有文档如果你想要自定义现有文档。Select Create a new document if you want to create a new document for the solution, or select Copy an existing document if you want to customize an existing document.

    如果创建一个新文档,请指定中的名称名称框,并使用选择的文档格式格式框。If you create a new document, specify the name in the Name box and select the format of the document by using the Format box. 有关可用格式的详细信息,请参阅的文档级自定义体系结构For more information about the available formats, see Architecture of document-level customizations.

    如果使用现有文档时,指定在文档的位置现有文档的完整路径框。If you use an existing document, specify the location of the document in the Full path of the existing document box. 可以使用绝对路径和 UNC 路径。You can use absolute and UNC paths. 不允许使用 HTTP、FTP 或其他协议的路径指定文档位置。Do not use HTTP, FTP, or other protocol paths to the document.

    位置具有以下格式:Locations have the following formats:

    • [drive]:[drive]:

    • \\Server\Share\\Server\Share

      不允许在该位置中使用以下字符:Do not use these characters in the location:

    • 星号 (*)Asterisk (*)

    • 竖线 (|)Vertical bar (|)

    • 冒号 (:)(接在驱动器号之后的情况除外)Colon (:) (Except following the drive letter.)

    • 双引号 (")(包含空格的路径不需要引号。)Double quotation mark (") (Paths that contain spaces do not need quotation marks.)

    • 小于 (<)Less than (<)

    • 大于 (>)Greater than (>)

    • 问号 (?)Question mark (?)

    • 百分号 (%)Percent sign (%)

    Note

    如果在 Word 2013Word 2013 项目中使用现有文档,则只能使用在 Word 2013Word 2013 项目中创建的或转换为该项目格式的文档。If you use an existing document in a Word 2013Word 2013 project, only use documents that were created in or converted to Word 2013Word 2013. 类似地,如果在 Word 2010 项目中使用现有文档,则只能使用在 Word 2010 中创建的或转换为该文档格式的文档。Similarly, if you use an existing document in a Word 2010 project, only use documents that were created in or converted to Word 2010. 如果使用 Word 早期版本创建的文档,将禁用文档中的某些功能。Certain features will be disabled in the document if you use a document that was created in an earlier version of Word. 如果尝试编写使用这些功能的代码,可能会在项目中出现错误。If you try to write code that uses these features, you might encounter errors in your project. 若要将文档转换,打开在Word 2013Word 2013或 Word 2010 中,在文件功能区上选项卡上,选择信息 > 转换To convert a document, open it in Word 2013Word 2013 or Word 2010, on the File tab on the ribbon, choose Info > Convert.

  8. 选择“完成”。Choose Finish.

  9. 在以下情况中将项目文件夹及其子文件夹添加到 Word“信任中心”中的受信任位置的列表中:Add the project folder and its subfolders to the list of trusted locations in the Trust Center in Word in the following cases:

    • 要创建 Word 文档的基于 .docm文件和文档包含 VBA 项目也可以在承载 Windows 窗体控件。You are creating a Word Document that is based on a .docm file, and the document contains a VBA project or hosts Windows Forms controls. 将项目文件夹添加到受信任位置的列表将有助于确保文档在设计时能够按预期正常工作。Adding the project folder to the list of trusted locations will help make sure that the document works as expected at design time.

    • 要创建 Word 模板项目基于 .dotx文件。You are creating a Word Template project that is based on a .dotx file. 必须将项目文件夹添加到受信任位置列表中,以便可以运行并调试项目。You must add the project folder to the list of trusted locations so that you can run and debug the project.

      有关如何将文档添加到受信任的位置的详细信息,请参阅 Microsoft Office Online 网站创建、 删除或更改你的文件的受信任位置For more information on how to add a document to the trusted locations, see the Microsoft Office Online web site Create, remove, or change a trusted location for your files.

请参阅See also