I have developed a word add-in using word javascript api. My Document .docx file is on server and i need to open that .docx document as a new word document on a button click in add-in.
Please guide me how i can open new document in word add-in.
Thanks.
There is a new method we are adding to the API that you can actually use to achieve this. Notice that is in preview, which means will be in production in a couple of months. You need latest Office version plus reference our preview office.js to try it. The office.js preview is here https://appsforoffice.microsoft.com/lib/beta/hosted/office.js
Check out this code sample on how easy is to do it.
 function onaddOpenDoc() {
        Word.run(function (context) {
          
          // this getDocumentAsBase64 assumes a valid base64-encoded docx file
            var myNewDoc = context.application.createDocument(getDocumentAsBase64());
            context.load(myNewDoc);
            return context.sync()
                .then(function () {
                    myNewDoc.open();
                    context.sync();
                }).catch(function (myError) {
                    //otherwise we handle the exception here!
                    showNotification("Error", myError.message);
                })
        }).catch(function (myError) { showNotification("Error", myError.message); });
    }If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With