简体   繁体   English

使用vue创建Excel加载项时。 如何根据Excel笔记本上的数据计算属性?

[英]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: 有关更多信息,请查看以下链接:

Get worksheets 获取工作表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 vue 组件中使用 Maatwebsite 导入 excel 文件? - How do I import a excel file using Maatwebsite in a vue component? 如何在角度js应用程序中使用alasql将数据导出到Excel时添加标题行和单元格格式? - How to add title row and cell formatting when exporting data to excel using alasql in angular js application? 如何在vue中将html导出为ex​​cel? - How do I export html to excel in vue? Datatable中导出数据到excel时如何添加行? - How to add rows when exporting data into excel in Datatable? 如何使用字符串作为 v-model 指令中的属性名称来访问 Vue 组件的数据属性? - How can I access my Vue component's data property using a string as it's property name in a v-model directive? 如何在 Vue.js 中将数据属性作为变量访问? - How can I access data property as variable in Vue.js? 我想在数据表中添加Excel按钮以进行Excel导出 - I want to add excel button in my data table for excel export 如何使用 vue.js 在 select 选项中添加数据图标属性 - How I can add data-icon attribute in select option using vue.js 如何使用javascript在excel中添加数据验证列表 - How to add data validation list in excel using javascript 如何使用 reactjs 或 javascript 使用文件路径读取 excel 文件中的数据 - How can I read the data in the excel file with reactjs or javascript using the path to the file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM