How to open a document in 'current window' in office add-in instead of opening in a new window?
Asked Answered
M

0

6

I'm working on Office 365 Word Add-in that opens a document.

When we open the document via context.application.createDocument(base64string).open(), it launches a new window instead of opening the document in current browser tab (in case of web Add-in) or current instance of word (in case of windows Add-in).

Here is my use case:

  1. Check if there is already an open document and ask the user to save or lose changes.

  2. Have an API to close the current open document e.g. context.document.close();

  3. Open a new document via context.application.createDocument(base64string).open(), so that the document is opened in the current window instead of opening in a new instance of word.

Is there any workaround to achieve this?

Cross posted here.

Thanks.

Mincey answered 28/5, 2020 at 20:45 Comment(3)
There is a workaround to open the document directly in the body of current document by replacing the current document (context.document.body.insertFileFromBase64(base64string, Word.InsertLocation.replace);), but it doesn't include headers, footers and sometimes the formatting is totally messed up.Mincey
Excellent! It's a great workaround! :):):)Kicksorter
I have the same question. And I have come up with exactly the same "workaround", but it's not really...satisfactory.Plunk

© 2022 - 2024 — McMap. All rights reserved.