myliang / x-spreadsheet

The project has been migrated to @wolf-table/table https://github.com/wolf-table/table
https://myliang.github.io/x-spreadsheet
MIT License
13.97k stars 1.67k forks source link

非初始化的導入多 sheet 後,切換 sheet 會出現 this.data is undefined 的問題 #701

Open mukiwu opened 1 week ago

mukiwu commented 1 week ago

初始化使用 loadData() 可以正常切換多個 sheet,但我想要做導入 Excel 的功能,所以點了按鈕之後才使用 loadData()

init = () => {
  spreadsheet.value = new Spreadsheet(spreadsheetContainer.value as HTMLDivElement, {
    showToolbar: true,
    showGrid: true,
    view: {
      width: () => props.mainWidth,
      height: () => props.mainHeight
    },
    row: {
      len: 500,
      height: 25
    }
  })
}

onClick = () => {
  spreadsheet.value.loadData(workbook.value)
}

結果要切換不同工作表時,就出現錯誤

Cannot destructure property 'rows' of 'this.data' as it is undefined.

目前看起來是沒有取到 this.data,導致後續問題 截圖 2024-06-27 18 02 24

有人碰過類似的問題嗎?

目前想到比較爛的解法是先銷毀再創建實例,但我也沒找到銷毀的方法 ....