生成首个 PowerPoint 任务加载项Build your first PowerPoint add-in

本文将逐步介绍如何生成 PowerPoint 任务窗格加载项。In this article, you'll walk through the process of building a PowerPoint add-in by using jQuery and the Office JavaScript API.

创建加载项Create the add-in

可以使用 Visual Studio 或其他任何编辑器创建 Office 加载项。 通过选择以下选项卡之一,告诉我们要使用哪个编辑器:You can create an Office Add-in by using Visual Studio or any other editor. Tell us what editor you'd like to use by choosing one of the following tabs:

先决条件Prerequisites

创建加载项项目Create the add-in project

  1. 在 Visual Studio 菜单栏中,依次选择“文件”**** > “新建”**** > “项目”****。On the Visual Studio menu bar, choose File > New > Project.

  2. 在“Visual C#”**** 或“Visual Basic”**** 下的项目类型列表中,展开“Office/SharePoint”****,选择“加载项”****,再选择“PowerPoint Web 加载项”**** 作为项目类型。In the list of project types under Visual C# or Visual Basic, expand Office/SharePoint, choose Add-ins, and then choose PowerPoint Web Add-in as the project type.

  3. 命名此项目,再选择“确定”****。Name the project, and then choose OK.

  4. 在“创建 Office 加载项”**** 对话框窗口中,选择“将新功能添加到 PowerPoint”****,再选择“完成”**** 以创建项目。In the Create Office Add-in dialog window, choose Add new functionalities to PowerPoint, and then choose Finish to create the project.

  5. 此时,Visual Studio 创建解决方案,且它的两个项目显示在“解决方案资源管理器”**** 中。Home.html 文件在 Visual Studio 中打开。Visual Studio creates a solution and its two projects appear in Solution Explorer. The Home.html file opens in Visual Studio.

探索 Visual Studio 解决方案Explore the Visual Studio solution

在用户完成向导后,Visual Studio 会创建一个包含两个项目的解决方案。When you've completed the wizard, Visual Studio creates a solution that contains two projects.

项目Project 说明Description
加载项项目Add-in project 仅包含 XML 清单文件,其中包含描述加载项的全部设置。这些设置有助于 Office 主机确定应何时激活加载项,以及应在何处显示加载项。Visual Studio 会生成此文件的内容,以便用户能够立即运行项目并使用加载项。可以随时更改这些设置,具体方法是修改 XML 文件。Contains only an XML manifest file, which contains all the settings that describe your add-in. These settings help the Office host determine when your add-in should be activated and where the add-in should appear. Visual Studio generates the contents of this file for you so that you can run the project and use your add-in immediately. You change these settings any time by modifying the XML file.
Web 应用项目Web application project 包含加载项的内容页,包括开发 Office 感知 HTML 和 JavaScript 页面所需的全部文件和文件引用。开发加载项时,Visual Studio 在本地 IIS 服务器上托管 Web 应用。准备好发布加载项后,需要将此 Web 应用项目部署到 Web 服务器。Contains the content pages of your add-in, including all the files and file references that you need to develop Office-aware HTML and JavaScript pages. While you develop your add-in, Visual Studio hosts the web application on your local IIS server. When you're ready to publish the add-in, you'll need to deploy this web application project to a web server.

更新代码Update the code

  1. Home.html 指定在加载项的任务窗格中呈现的 HTML。 在 Home.html 中,将 <body> 元素替换为以下标记,并保存文件。Home.html specifies the HTML that will be rendered in the add-in's task pane. In Home.html, replace the <body> element with the following markup and save the file.

    <body class="ms-font-m ms-welcome">
        <div id="content-header">
            <div class="padding">
                <h1>Welcome</h1>
            </div>
        </div>
        <div id="content-main">
            <div class="padding">
                <p>Select a slide and then choose the buttons to below to add content to it.</p>
                <br />
                <h3>Try it out</h3>
                <button class="ms-Button" id="insert-image">Insert Image</button>
                <br/><br/>
                <button class="ms-Button" id="insert-text">Insert Text</button>
            </div>
        </div>
    </body>
    
  2. 打开 Web 应用项目根目录中的文件“Home.js”****。 此文件指定加载项脚本。 将整个内容替换为以下代码,并保存文件。Open the file Home.js in the root of the web application project. This file specifies the script for the add-in. Replace the entire contents with the following code and save the file.

    'use strict';
    
    (function () {
    
        Office.onReady(function() {
            // Office is ready
            $(document).ready(function () {
                // The document is ready
                $('#insert-image').click(insertImage);
                $('#insert-text').click(insertText);
            });
        });
    
        function insertImage() {
            Office.context.document.setSelectedDataAsync(getImageAsBase64String(), {
                coercionType: Office.CoercionType.Image,
                imageLeft: 50,
                imageTop: 50,
                imageWidth: 400
            },
                function (asyncResult) {
                    if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                        console.log(asyncResult.error.message);
                    }
                });
        }  
    
        function insertText() {
            Office.context.document.setSelectedDataAsync("Hello World!",
                function (asyncResult) {
                    if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                        console.log(asyncResult.error.message);
                    }
                });
        }
    
        function getImageAsBase64String() {
            return 'iVBORw0KGgoAAAANSUhEUgAAAZAAAAEFCAIAAABCdiZrAAAACXBIWXMAAAsSAAALEgHS3X78AAAbX0lEQVR42u2da2xb53nH/xIpmpRMkZQs2mZkkb7UV3lifFnmNYnorO3SLYUVpFjQYoloYA3SoZjVZRi2AVtptF+GNTUzbGiwDQu9deg2pCg9FE3aYQ3lDssw2zGNKc5lUUr6ItuULZKiJUoyJe2DFFsXXs6VOpf/D/kS6/Ac6T2Hv/M8z3nf5zTMz8+DEEL0QCOHgBBCYRFCCIVFCKGwCCGEwiKEEAqLEEJhEUIIhUUIIRQWIYTCIoQQCosQQigsQgiFRQghFBYhhFBYhBAKixBC1hArh2CBwtlYaTRV6ac2f7Cx2Q3AsTfEsSKEwlprYQ3Gpt4bFLixfU+vpdltCwTte0JNHQFrR4ADSEgdaGCL5AVGvhkSLqyV1t/gd+wN2feGHHtClBchFJbq3Hq5b+LCGfn7sfl7nI+HWw710VyEUFhqkf1BJPuDkwrusOXgsfW94ZZDfRxb8oBCEpn4yn90BmF1ozUIq5sjVCOb4RCoxMSFMxMXzlg3+D1fjDgfD3NAzE4ph6EwMlWjeKsLziDaQvCE0BbimDHCquyX8/Fb33lapZ3b9/RueD5q8wc5zuYl2VfDVqvx9MLbB28fHCwvUFjLmUknr/3xw6oewvPMNzzPRDjUZmQsgfNHpX/cewzePvgYp1NYS/j4yw1qH8K+p3fTS/GFKV3ERLw/gCuvyN2Jww9fGP4BM5e6ONP9ATZ/j9qHmHpvcOSbobnJHEfbXBSSCuykmMbwSZwNYDiCkkkvIQpryQ1sT6guueclOotIp5Rf1NZIjMIyNfZ6LbuZSV8a/W6YA05kaWvoOM6FlIndKCxdRlh1XCc4ceFM/o0ox9wsqDRHITuItx9G2kQXEoW1ZCya3S0Hj9XtcNkfRJgYmgVfGFaXWjv/4Os4FzJJVYvCWkbz4fpNTJ+b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3AFYedkpg9g3PNNWumXuys9LP33JmnvH0jBbc+N79+zOjoCg6+dKVESQbsrwisJauwiL+aAeQ6r/+9HsT79mnUrbADQIs1vNinshifcHRL9gyazVTwpLIVuJaoDF1le6Yzp374fPNV3/kdgvjPVTVZspD0cwfFLK78MIi1QL1zNxZBMS3zu/Gi4e1BfjqdLfH26avS32c6UZWDZW6EJTyuFin8Q3V1JYpKKqPhhQzFMLsPWVzsLn5Pz3HrHOz0gJyypV3Es5nAtJv67MWnGnsKrcHHMYCkt8VVd1WL3SVWw1/71HGiTZCsBMES1lhTUUlnUXNGt4RWFVtpWcG2AV2PpKR0znZv/h0xaptgIw21ZuVeBwRO6N0MTzjTkPq462AqtXemLuP37fMj0i69v10JGV/1RISqyyL7vtmbekQGGtQj1bsfWVrpLBxvdek3Xjm0HT1kdW/uv7ShQETJwSUlirwnWVbAW2vtITsz9+UW6kPr2q4j6WkP5YkMKisMokg+moivtnuV0/4ZXl+k9k7qN4d9UqQgnt0lbj6TXzmaGwlpCOSnkBqtDwiq2vdMP85e/L30mZVz1Le2ElwysKqzyK3ACr5INEL8Ia+icF9rLx4Mp8UJHbYSuFRSD1fYJC74psfaWrb0X+Xbnh1SysWx9d9k8SXqfECIvCqshYQsWds3qlI8ZT8vcxM7mqgFVIUlgUlnKUcmrtma2v9EVeAWEV78Kxd3lMfU+JC8zcFXcKqy7QVuajTMWd4ZUSNMzPz/PyIoQwwiKEEAqLEEJhEUIIhUUIIRQWIYTCIoQQCosQQigsQgiFRQghFBYhhFBYhBAKixBCKCxCCKGwCCGG4/8BAjn5LoppTCkAAAAASUVORK5CYII=';
        }
    
    })();
    
  3. 打开 Web 应用项目根目录中的文件“Home.css”****。 此文件指定加载项自定义样式。 将整个内容替换为以下代码,并保存文件。Open the file Home.css in the root of the web application project. This file specifies the custom styles for the add-in. Replace the entire contents with the following code and save the file.

    #content-header {
        background: #2a8dd4;
        color: #fff;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 80px; 
        overflow: hidden;
    }
    
    #content-main {
        background: #fff;
        position: fixed;
        top: 80px;
        left: 0;
        right: 0;
        bottom: 0;
        overflow: auto; 
    }
    
    .padding {
        padding: 15px;
    }
    

更新清单Update the manifest

  1. 打开加载项项目中的 XML 清单文件。Open the XML manifest file in the add-in project. 此文件定义的是加载项设置和功能。This file defines the add-in's settings and capabilities.

  2. ProviderName 元素具有占位符值。 将其替换为你的姓名。The ProviderName element has a placeholder value. Replace it with your name.

  3. DisplayName 元素的 DefaultValue 属性有占位符。The DefaultValue attribute of the DisplayName element has a placeholder. 将它替换为“My Office Add-in”****。Replace it with My Office Add-in.

  4. Description 元素的 DefaultValue 属性有占位符。The DefaultValue attribute of the Description element has a placeholder. 将它替换为“A task pane add-in for PowerPoint”****。Replace it with A task pane add-in for PowerPoint.

  5. 保存文件。Save the file.

    ...
    <ProviderName>John Doe</ProviderName>
    <DefaultLocale>en-US</DefaultLocale>
    <!-- The display name of your add-in. Used on the store and various places of the Office UI such as the add-ins dialog. -->
    <DisplayName DefaultValue="My Office Add-in" />
    <Description DefaultValue="A task pane add-in for PowerPoint"/>
    ...
    

试用Try it out

  1. 使用 Visual Studio 的同时,按 F5 或选择“开始”**** 按钮启动 PowerPoint,以测试新建的 PowerPoint 加载项,功能区中显示有“显示任务窗格”**** 加载项按钮。加载项本地托管在 IIS 上。Using Visual Studio, test the newly created PowerPoint add-in by pressing F5 or choosing the Start button to launch PowerPoint with the Show Taskpane add-in button displayed in the ribbon. The add-in will be hosted locally on IIS.

  2. 在 PowerPoint 中,插入新的空白幻灯片,再依次选择“主页”**** 选项卡和功能区中的“显示任务窗格”**** 按钮,以打开加载项任务窗格。In PowerPoint, insert a new blank slide, choose the Home tab, and then choose the Show Taskpane button in the ribbon to open the add-in task pane.

    突出显示了“显示任务窗格”按钮的 PowerPoint 屏幕截图

  3. 在任务窗格中,选择“插入图像”**** 按钮,以便将图像添加到选定幻灯片。In the task pane, choose the Insert Image button to add an image to the selected slide.

    幻灯片上显示有狗图像的 PowerPoint 屏幕截图

  4. 在任务窗格中,选择“插入文本”**** 按钮,以便将文本添加到选定幻灯片。In the task pane, choose the Insert Text button to add text to the selected slide.

    幻灯片上显示有狗图像和文本“Hello World”的 PowerPoint 屏幕截图

后续步骤Next steps

恭喜!已成功创建 PowerPoint 任务窗格加载项!Congratulations, you've successfully created a PowerPoint add-in! 接下来,请详细了解 PowerPoint 加载项功能,并跟着 PowerPoint 加载项教程一起操作,生成更复杂的加载项。Next, learn more about the capabilities of a PowerPoint add-in and build a more complex add-in by following along with the PowerPoint add-in tutorial.