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. Right now im calling a method when computing the property but I think its not running the code in the excel.run. In the code bellow only the a and the d get pushed to the array.
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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.