You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用VSCode开发Word插件时调用insertDrawingCanvas方法报错:该方法不存在的问题求助

VSCode开发Word插件时调用insertDrawingCanvas方法报错:该方法不存在的问题求助

我是个刚接触Word插件开发的新手,目前正在用VSCode和JavaScript搭建我的第一个插件,是基于Office官方的入门示例扩展来做的。我的需求是给现有文档的特定区域自动画线,现在先想实现最基础的图形绘制功能,结果第一步就卡住了。

我修改了taskpane.js文件,代码如下:

Office.onReady((info) => {
  if (info.host === Office.HostType.Word) {
    document.getElementById("sideload-msg").style.display = "none";
    document.getElementById("app-body").style.display = "flex";
    document.getElementById("run").onclick = run;
  }
});

export async function run() {
  return Word.run(async (context) => {
    // Insert a paragraph at the end of the document.
    const paragraph = context.document.body.insertParagraph("Hello Wonderful World", Word.InsertLocation.end);
    // Change the paragraph color to blue.
    paragraph.font.color = "blue";

    // Start new part
    // Insert a drawing canvas
    const canvas = context.document.body.insertParagraph("").insertDrawingCanvas(0, 0, 200, 100);
    // Insert a shape into the canvas
    const shape = canvas.insertShape("rectangle", 10, 10, 150, 70);
    // Change the shape's fill color
    shape.fill.color = "red";
    // End new part

    await context.sync();
  });
}

我知道这段代码不是画线的,但现在只想先成功绘制出点什么东西。结果点击任务面板的「Run」按钮后,完全没有图形被绘制出来,还抛出了错误:

Uncaught runtime errors: ERROR context.document.body.insertParagraph(...).insertDrawingCanvas is not a function

我感觉自己肯定漏掉了某个关键的点,但搜了好多资料都没找到问题所在,有没有大佬能帮忙看看问题出在哪呀?


内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 07:10:28