找回密码
 立即注册

QQ登录

只需一步,快速开始

Joestar.Xu SpreadJS 开发认证

超级版主

38

主题

6764

帖子

8836

积分

超级版主

Rank: 8Rank: 8

积分
8836

SpreadJS 认证SpreadJS 高级认证

Joestar.Xu SpreadJS 开发认证
超级版主   /  发表于:2023-11-30 15:21  /   查看:719  /  回复:0
本帖最后由 Ellia.Duan 于 2023-12-26 16:48 编辑

问题背景:部分客户希望能够修改设计器创建的表格默认样式,但是现在没有相关的接口能够实现这样的需求,能否通过代码来实现呢?


image.png707966918.png

解决方案:可以通过重写创建表格的指令来实现这样的需求,创建表格的指令为:“Designer.createDefaultTable”,在这个指令中将table的style设置为想要设置的样式即可实现,参考代码如下:
  1. let command = {
  2.   canUndo: true,
  3.   execute: function (context, options, isUndo) {
  4.     let Commands = GC.Spread.Sheets.Commands;
  5.     if (isUndo) {
  6.       Commands.undoTransaction(context, options);
  7.       return true;
  8.     } else {
  9.       Commands.startTransaction(context, options);
  10.       context.suspendPaint();
  11.       let sheet = context.getActiveSheet();
  12.       let selection = sheet.getSelections()[0];

  13.       let name = Date.now();
  14.       console.log(name);

  15.       let table = sheet.tables.add(
  16.         name,
  17.         selection.row,
  18.         selection.col,
  19.         selection.rowCount,
  20.         selection.colCount,
  21.         undefined
  22.       );
  23.       table.style(undefined);
  24.       context.resumePaint();
  25.       Commands.endTransaction(context, options);
  26.       return true;
  27.     }
  28.   },
  29. };
  30. let commandManager = spread.commandManager();
  31. commandManager.register("Designer.createDefaultTable", command);
复制代码

那么如果在SpreadJS中,如何创建一个无样式Table呢?可以参考下这篇文章:

https://gcdn.grapecity.com.cn/showtopic-197752-1-1.html



SpreadJS 17.0.8 | GcExcel 7.1.1 已发布~

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部