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

相關問題