20金币
- class StatementF extends GC.Spread.CalcEngine.Functions.AsyncFunction {
- cellRequestMap: Map<string, CellRequest>;
- constructor(name: string) {
- super(name, 1, 255);
- this.cellRequestMap = new Map<string, CellRequest>();
- }
- defaultValue(): any {
- return "Loading";
- }
- evaluateAsync(context: GC.Spread.CalcEngine.AsyncEvaluateContext): any {
- const args = arguments;
- const p = arguments[0]
- console.log(p)
- const sheetName = p.ctx.source.getSheet().name()
- if (args.length != 3) {
- context.setAsyncResult("参数异常");
- return;
- }
- console.log(sheetName, p.row, p.col)
- let mapKey = sheetName + '-' + p.row + '-' + p.col
- if (this.cellRequestMap.has(mapKey)) {
- const cellMap = this.cellRequestMap.get(mapKey)
- if (cellMap) {
- cellMap.formula.push(args[1])
- cellMap.argStr.push(args[2])
- cellMap.context.push(context)
- }
- } else {
- this.cellRequestMap.set(sheetName + '-' + p.row + '-' + p.col, {
- formula: [args[1]],
- argStr: [args[2]],
- context: [context]
- });
- }
- // 设置默认值,默认值是文本类型,和其他的一起的时候会报#NAME?
- context.setAsyncResult("Loading...");
- }
- }
复制代码 如代码,我定义了一个异步函数,然后我使用
- spread.addCustomFunction(StatementFun)
复制代码 添加后,在页面中不生效,显示为#NAME?,这个异步函数不也是继承自定义函数吗,为什么添加不生效
|
|