【发布时间】:2021-11-03 14:31:46
【问题描述】:
我有一个类应该将 excel 表的值保留为属性。如果我将getValues() 放入类构造函数中,则脚本将失败并出现 failed to load [code] [library] 错误(来自编辑器控制台输出的完整消息)。
function main(wkb: ExcelScript.Workbook){
const tbl = wkb.getTable('test')
const info = new Info(tbl)
}
class Info {
table: ExcelScript.Table
vals: string[][]
constructor(table: ExcelScript.Table){
this.table = table
// failing here, line commented for workaround
this.vals = table.getValues() as unknown[][] as string[][]
}
getVals(){
// this will work (if not called from the constructor)
this.vals = this.table.getRange().getValues() as unknown[][] as string[][]
}
}
作为一种解决方法,我在类实例初始化后调用getVals() 方法,但我想避免这种额外的调用。
我在这里做错了什么?是与 TypeScript 的工作原理(刚开始学习)有关还是与 Office Script API 相关?
【问题讨论】:
-
我相信这是一个与如何使用构造函数有关的限制。您可以在此处查看更多信息:stackoverflow.com/questions/68659405/…
标签: typescript office-scripts excel-online