在 Office-JS 库中,可以获取工作簿中的所有工作表。也可以获得一个特定的工作表。是否可以在工作簿中获取选定的工作表?
问问题
13 次
1 回答
0
以下代码示例获取工作表的集合,加载每个工作表的名称属性,并向控制台写入消息:
Excel.run(function (context) {
var sheets = context.workbook.worksheets;
sheets.load("items/name");
return context.sync()
.then(function () {
if (sheets.items.length > 1) {
console.log(`There are ${sheets.items.length} worksheets in the workbook:`);
} else {
console.log(`There is one worksheet in the workbook:`);
}
sheets.items.forEach(function (sheet) {
console.log(sheet.name);
});
});
}).catch(errorHandlerFunction);
以下代码示例获取活动工作表,加载其名称属性,并将消息写入控制台。
Excel.run(function (context) {
var sheet = context.workbook.worksheets.getActiveWorksheet();
sheet.load("name");
return context.sync()
.then(function () {
console.log(`The active worksheet is "${sheet.name}"`);
});
}).catch(errorHandlerFunction);
有关详细信息,请参阅使用 Excel JavaScript API 处理工作表。
于 2022-02-20T14:52:51.080 回答