我已经使用示例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
作为HTML
或Text
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));
}
});
我很高兴有人可以阐明这个问题。