insertInlinePictureFromBase64 在 Word2016 中未定义

insertInlinePictureFromBase64 is undefined in Word2016

我正在尝试使用以下方法将图像插入到 word 文档中: bodyObject.insertInlinePictureFromBase64,但我收到未定义方法的错误。 然而,here 列举的其余方法似乎都可用,只有这个缺失。如果这个真的不可用,我正在寻找一些许可?如果确实暂时没有,那么在不久的将来是否可以使用?

Oskar,这是一个很好的问题,感谢您的提问。我非常确定您看到此问题的原因是因为在 Word 版本中您使用的 Word 1.2 要求集可能不受支持,您需要更新 Word。为了检查这一点,请转到文件-> 帐户并确保您的构建是 6568+(检查下图)。如果您没有 6568.xxxx+ 请确保更新您的 Office。

现在,要安全地使用此方法,您需要在运行时确保执行您的加载项的主机是否确实支持 1.2 要求集,并且可以通过 "isSetSupported" 方法轻松检查.看这个例子:

 if (Office.context.requirements.isSetSupported("WordApi", "1.2")) {
         Word.run(function (context){
        var myBase64File = getDocumentAsBase64(); // assumes gets a docx file as base64
        context.document.body.insertFileFromBase64(myBase64File, "end");
        return context.sync();
    })
          .catch(function (myError) {
              //otherwise we handle the exception here!
              app.showNotification("Error", myError.message);
          })        }
    else {
        //if you reach this code it means that the Word executing this code does not yet support the 1.2 requirement set. in this case you can also insert a paragraph and then insert the document on the paragraph.

        app.showNotification("Error. This functionality requires Word with at least January update!! (check  builds 6568+)");   

    }

最后要检查每个要求集支持哪些 API,请参阅此 page

我希望你觉得这个 post 很有帮助。

...另外我刚刚注意到你说你想插入一张图片。 insertFileFromBase64 方法旨在插入整个 Word 文档。 (即 docx 文件)如果要插入图像,则需要使用 Body.insertInlinePictureFromBase64(base64EncodedImage, insertLocation) 方法。 go here for reference 这也是 1.2 要求集的一部分。