[英]When using vue to create an Excel Add-in. How can I compute a property based on data on the excel notebook?
I want to get a list of the names of the sheets to create a drop drop down in my add in. I tried to do it via aa computed property but you cant run async functions to interact whit excel when computing a property. 我想获得工作表名称的列表,以在我的加载项中创建一个下拉列表。我试图通过一个计算属性来执行此操作,但是在计算属性时,您无法运行异步函数来与excel进行交互。 Right now im calling a method when computing the property but I think its not running the code in the excel.run. 现在我在计算属性时调用了一个方法,但是我认为它没有运行excel.run中的代码。 In the code bellow only the a and the d get pushed to the array. 在下面的代码中,只有a和d被压入数组。
computed: { formats: function () { return this.getSheetNames() } }, methods: { getSheetNames () { var sheetNames = ['a'] window.Excel.run(async (context, sheetNames) => { let promise = Promise.resolve(['b']) let list = await promise sheetNames.push(list) sheetNames.push('c') }) sheetNames.push('d') return sheetNames }
Please use the code below: 请使用以下代码:
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);
}
});
})
For more information, please review the following link: 有关更多信息,请查看以下链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.