有没有一种方法可以将Excel内容作为HTML /文本(如Word加载项)获取?

时间:2019-01-02 11:06:23

标签: jquery office-js excel-addins

我已经使用示例Excel代码通过add-in获得了出色的表现:

async function run() {
    try {
            await Excel.run(async context => {

                // const range = context.workbook.getSelectedRange();

                const sheetName = 'Sheet1';
                const rangeAddress = 'F1:F20';
                const worksheet = context.workbook.worksheets.getItem(sheetName);
                const range = worksheet.getRange(rangeAddress);
                range.load('text');

                await context.sync();
                console.log(range.text);
            });
        } catch(error) {
            OfficeHelpers.UI.notify(error);
            OfficeHelpers.Utilities.log(error);
        };
}

在这里,它为您提供了Excel F列的数据数组。

没有办法将整个worksheet作为HTMLText like what we do in Word add-in:

// Run a batch operation against the Word object model.
Word.run(function (context) {

    // Create a proxy object for the document body.
    var body = context.document.body;

    // Queue a commmand to get the HTML contents of the body.
    var bodyHTML = body.getHtml();

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    return context.sync().then(function () {
        console.log("Body HTML contents: " + bodyHTML.value);
    });
})
.catch(function (error) {
    console.log("Error: " + JSON.stringify(error));
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

我很高兴有人可以阐明这个问题。

0 个答案:

没有答案