0

我正在使用word javaScript API来开发Word插件,我需要从服务器加载文件并将内容插入到文件,目前.DOCX文件工作正常,并插入到文档中,但是当我尝试将.RTF格式文件的内容插入到文档时,Word会引发以下错误:如何将RTF格式文件(.rtf)文件内容插入word文档中使用word javascript API

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); 

请教我如何插入RTF格式的文件内容在word文档中。 谢谢。

+0

你能发布一个完整的代码片段吗? –

+0

我正在研究这个。与此同时,RTF文件往往比等效的docx文件大得多,并且计时问题可能会影响您是否可以放弃对context.sync()调用的错误处理。确保您调用insertFileFromBase64的Word.run在insertFileFromBase64调用之后的某处有一个“return context.sync()”。不要忘记关键字“返回”。它必须在那里。 –

+0

@ RickKirkham-微软谢谢,我错过了回报。 – Amit

回答

0

今天API不支持插入RTF文件,请尝试docx格式。 Btw你的错误似乎是你没有调用return context.sync()。

+0

谢谢,我在context.sync之前缺少return。有没有什么方法可以读取RTF并将RTF转换为DOCX或任何有关如何管理RTF文件的建议? – Amit

相关问题