使用JavaScript Office API以编程方式打开Excel文档

问题描述:

如何使用javascript office API以编程方式打开文档?

How to programatically open a document using javascript office api ?

是否可以使用javascript office api插入文档,还是可以访问文档xml?像这样

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));
        }
});

在Word中,加载项可以使用

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

在Excel中,此API不可用.或者,您可以启用文件下载而不是替代文件的下载:例如,您可以向文件添加HTML链接,然后让用户下载它,也可以使用JavaScript触发下载.

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(Office加载项的PM)

-Michael (PM for Office add-ins)