首页 > 解决方案 > 如何通过 office.js 插件在 powerpoint 中插入图表/表格

问题描述

我计划创建一个PowerPoint插件,它将自动初始化一个包含数据库中数据的ppt。如何将图表/表格插入/更新到幻灯片中?

谢谢!

标签: powerpointoffice-js

解决方案


您可以使用OfficeJS API。例如,以下函数使用 Office JavaScript API 将图像插入到文档中。笔记:

  • coercionType指定为请求的第二个参数的选项指示setSelectedDataAsync要插入的数据类型。

  • asyncResult对象封装了setSelectedDataAsync请求的结果,包括请求失败时的状态和错误信息。

function insertImageFromBase64String(image) {
    // Call Office.js to insert the image into the document.
    Office.context.document.setSelectedDataAsync(image, {
        coercionType: Office.CoercionType.Image
    },
        function (asyncResult) {
            if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                showNotification("Error", asyncResult.error.message);
            }
        });
}

您可以在教程:创建 PowerPoint 任务窗格加载项中了解更多相关信息。


推荐阅读