![](/img/trans.png)
[英]How do I import a excel file using Maatwebsite in a vue component?
[英]When using vue to create an Excel Add-in. How can I compute a property based on data on the excel notebook?
我想获得工作表名称的列表,以在我的加载项中创建一个下拉列表。我试图通过一个计算属性来执行此操作,但是在计算属性时,您无法运行异步函数来与excel进行交互。 现在我在计算属性时调用了一个方法,但是我认为它没有运行excel.run中的代码。 在下面的代码中,只有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 }
请使用以下代码:
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);
}
});
})
有关更多信息,请查看以下链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.