簡體   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?

我想獲得工作表名稱的列表,以在我的加載項中創建一個下拉列表。我試圖通過一個計算屬性來執行此操作,但是在計算屬性時,您無法運行異步函數來與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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM