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));
        }
});
Nicu
  • 3,476
  • 4
  • 23
  • 43
  • this is for browser? you can't. Or node.js? – JMR Mar 08 '16 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 – Nicu Mar 08 '16 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);`. – Miro J. Sep 08 '16 at 15:41

1 Answers1

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)

Michael Saunders
  • 2,662
  • 1
  • 12
  • 21