【发布时间】:2017-03-16 09:31:57
【问题描述】:
我正在使用 word javaScript Api 开发 Word 插件,我需要从服务器加载文件并将内容插入到文档中,目前 .docx 文件工作正常并插入到文档中,但是当我尝试将 .rtf 格式的文件内容插入到文档中,word 会抛出以下错误:
Error: {"name":"OfficeExtension.Error","code":"RunMustReturnPromise","message":"The batch function passed to the \".run\" method didn't return a promise. The function must return a promise, so that any automatically-tracked objects can be released at the completion of the batch operation. Typically, you return a promise by returning the response from \"context.sync()\".","traceMessages":[],"debugInfo":{},"stack":"RunMustReturnPromise: The batch function passed to the \".run\" method didn't return a promise. The function must return a promise, so that any automatically-tracked objects can be released at the completion of the batch operation. Typically, you return a promise by returning the response from \"context.sync()\".\n at t.throwError (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:21:233250)\n at Anonymous function (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:21:202009)\n at yi (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.0
我正在使用以下代码插入内容:
range.insertFileFromBase64(myBase64, Word.InsertLocation.start);
请告知我如何在 Word 文档中插入 RTF 格式的文件内容。 谢谢。
【问题讨论】:
-
能发一个完整的sn-p代码吗?
-
我正在研究这个。同时,RTF 文件往往比等效的 docx 文件大得多,并且时间问题会影响您是否可以摆脱对 context.sync() 调用的错误处理。确保调用 insertFileFromBase64 的 Word.run 在调用 insertFileFromBase64 之后的某处有一个“return context.sync()”。不要忘记关键字“return”。它必须在那里。
-
@RickKirkham-Microsoft 谢谢,我错过了回报。
标签: ms-word office365 office-js word-addins javascript-api-for-office