【问题标题】:How to insert Rich Text Format(.rtf) file content into word doc using word javascript API如何使用 word javascript API 将富文本格式(.rtf)文件内容插入 word doc
【发布时间】: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


【解决方案1】:

目前 API 不支持插入 RTF 文件,请尝试使用 docx 格式。 顺便说一句,您的错误似乎是您没有调用 return context.sync()。

【讨论】:

  • 谢谢,我在 context.sync 之前错过了返回。有什么方法可以读取 RTF 并将 RTF 转换为 DOCX 或任何建议我如何管理 RTF 文件?
猜你喜欢
  • 1970-01-01
  • 2021-10-20
  • 1970-01-01
  • 2011-12-30
  • 1970-01-01
  • 1970-01-01
  • 2011-04-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多