3

How to programatically open a document using javascript office api ?

Is there a way to insert a document using javascript office api Or to get access to the document xml ? Something like this

Excel.run(function (ctx) { 
    var application = ctx.workbook.application;
    application.load('newXmlWorkbook', worbookInXmlFormat);
    return ctx.sync().then(function() {
        console.log(application.calculationMode);
    });
}).catch(function(error) {
        console.log("Error: " + error);
        if (error instanceof OfficeExtension.Error) {
            console.log("Debug info: " + JSON.stringify(error.debugInfo));
        }
});
3
  • this is for browser? you can't. Or node.js? Commented Mar 8, 2016 at 14:00
  • No, I have an Excel add-in built with javascript office api and I have a cloud storage with documents, I want when I click the document from my add-in, to load the document in Excel Commented Mar 8, 2016 at 14:35
  • 1
    In a similar scenario, we open documents within a new instance of Word with this JS code window.open('ms-word:ofv|u|' + filename); For Excel, window.open('ms-excel:ofv|u|' + filename);. Commented Sep 8, 2016 at 15:41

1 Answer 1

3

In Word an add-in can insert an entire document with the Document.insertFileFromBase64() method.

In Excel this API isn't available. As an alternative, you can enable a download of the file instead of a replacement: for example, you can add an HTML link to the file and let the user download it or you can trigger the download yourself in JavaScript.

-Michael (PM for Office add-ins)

Sign up to request clarification or add additional context in comments.

3 Comments

Hi, Michael! Could you take a look at the question: stackoverflow.com/questions/36063158/…
Is Document.insertFileFromBase64() still valid?
@Amitabh looks like the method moved to Body class: dev.office.com/reference/add-ins/word/body

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.