Javascript 使用vue创建Excel加载项时。如何根据excel笔记本上的数据计算属性?
我想获得工作表名称的列表,以便在我的外接程序中创建下拉列表。我试图通过计算属性来实现,但在计算属性时,无法运行异步函数与excel交互。现在我在计算属性时调用一个方法,但我认为它没有运行excel.run中的代码。在下面的代码中,只有a和d被推送到数组中Javascript 使用vue创建Excel加载项时。如何根据excel笔记本上的数据计算属性?,javascript,excel,sharepoint,office365,office-js,Javascript,Excel,Sharepoint,Office365,Office Js,我想获得工作表名称的列表,以便在我的外接程序中创建下拉列表。我试图通过计算属性来实现,但在计算属性时,无法运行异步函数与excel交互。现在我在计算属性时调用一个方法,但我认为它没有运行excel.run中的代码。在下面的代码中,只有a和d被推送到数组中 计算:{ 格式:函数(){ 返回此值。getSheetNames() } }, 方法:{ getSheetNames(){ var sheetNames=['a'] window.Excel.run(异步(上下文、表名)=>{ 让promis
计算:{
格式:函数(){
返回此值。getSheetNames()
}
},
方法:{
getSheetNames(){
var sheetNames=['a']
window.Excel.run(异步(上下文、表名)=>{
让promise=promise.resolve(['b'])
等待承诺
sheetNames.push(列表)
sheetNames.push('c')
})
sheetNames.push('d')
返回图纸名称
}
请使用以下代码:
Window.Excel.run(async(context) {
var sheets = context.workbook.worksheets;
sheets.load("items/name");
var sheetNames = [];
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:`);
}
for (var i in sheets.items) {
sheetNames.push(sheets.items[i].name);
}
});
})
有关更多信息,请查看以下链接:
请使用以下代码:
Window.Excel.run(async(context) {
var sheets = context.workbook.worksheets;
sheets.load("items/name");
var sheetNames = [];
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:`);
}
for (var i in sheets.items) {
sheetNames.push(sheets.items[i].name);
}
});
})
有关更多信息,请查看以下链接:
如果我的回复对您有帮助,请将该回复标记为答案,这将使其他遇到类似问题的人更容易在此论坛中搜索有效解决方案。如果我的回复对您有帮助,请将该回复标记为答案,这将使其他遇到类似问题的人更容易在此论坛中搜索有效解决方案。