我有几个“命名”范围。我试图获取范围的名称,而不是值。
我尝试过以下方法:
$("#get-values").click(getValues);
async function getValues() {
try {
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("FormName");
const valm = sheet.names;
valm.load("names");
await context.sync();
console.log(JSON.stringify(valm.names));
});
} catch (error) {
OfficeHelpers.UI.notify(error);
OfficeHelpers.Utilities.log(error);
}
}
我不知道如何从上面的脚本中获取名称
最佳答案
names
集合可在工作簿级别访问:
async function run() {
await Excel.run(async (context) => {
var names = context.workbook.names;
names.load();
await context.sync();
console.log(JSON.stringify(names));
});
}
这将产生一个 NamedItemCollection
,其中包含与此类似的 NotedItems
:
{
"comment": "",
"name": "Range Name",
"scope": "Workbook",
"type": "Range",
"value": "Sheet1!$A$1:$C$1",
"visible": true
}
范围的地址保存在value
属性中。您可以使用它来确定找到给定范围的哪个工作表。
关于javascript - 如何获取office.js中的所有名称(而不是值)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48987919/