找回密码
 立即注册

QQ登录

只需一步,快速开始

美的人都早起

注册会员

10

主题

27

帖子

161

积分

注册会员

积分
161
美的人都早起
注册会员   /  发表于:2021-7-19 11:15  /   查看:4387  /  回复:13
1金币

复制代码
let tableStyle = new GC.Spread.Sheets.Tables.TableTheme();
let thinBorder = new GC.Spread.Sheets.LineBorder("#d3d6db", GC.Spread.Sheets.LineStyle.thin);
tableStyle.wholeTableStyle(new GC.Spread.Sheets.Tables.TableStyle("#f5f7fa", "#666", "normal 10pt arial", thinBorder, thinBorder, thinBorder, thinBorder, thinBorder, thinBorder));
sheet.tables.add("dataTable", 0, 0, arr.length, that.columnList.length, tableStyle);
sheet.options.protectionOptions = {
  allowSelectLockedCells: true,
  allowSelectUnlockedCells: true,
  allowFilter: true,
  allowSort: true,
  allowResizeRows: true,
  allowResizeColumns: true,
  allowEditObjects: false,
  allowDragInsertRows: false,
  allowDragInsertColumns: false,
  allowInsertRows: false,
  allowInsertColumns: false,
  allowDeleteRows: false,
  allowDeleteColumns: false,
  allowOutlineColumns: false,
  allowOutlineRows: false
};
sheet.options.isProtected = true;
这样写报错 报表格不能相交

最佳答案

查看完整内容

我的代码放到例子里没有报错 sheet.tables.add("dataTable", 0, 0, arr.length, that.columnList.length, tableStyle); 之前报错应该是这个方法走了多遍 因为我的数据是变化的 let table = sheet.tables.all()[0]; debugger; if(!!(table)){ table.style(tableStyle) } else { sheet.tables.add("dataTable", 0, 0, arr.length, that.columnList.len ...

13 个回复

倒序浏览
最佳答案
最佳答案
美的人都早起
注册会员   /  发表于:2021-7-19 11:15:15
来自 13#
Derrick.Jiao 发表于 2021-7-19 14:25
从您的代码中这边没有看到初始化表格的代码,您需要先add再修改才有效,请在此demo上复现您的问题。

我的代码放到例子里没有报错
sheet.tables.add("dataTable", 0, 0, arr.length, that.columnList.length, tableStyle);
之前报错应该是这个方法走了多遍 因为我的数据是变化的
let table = sheet.tables.all()[0];
            debugger;
            if(!!(table)){
              table.style(tableStyle)
            } else {
              sheet.tables.add("dataTable", 0, 0, arr.length, that.columnList.length, tableStyle);
            }
添加这个判断后问题就解决了
回复 使用道具 举报
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2021-7-19 11:51:24
2#
您好,这边根据您的描述用上述代码未能复现您的问题,请问您的原始表单中是否已有表格了呢,建议您提供完整可运行的demo这边调研一下。
image.png305447081.png
回复 使用道具 举报
美的人都早起
注册会员   /  发表于:2021-7-19 13:10:40
3#
Derrick.Jiao 发表于 2021-7-19 11:51
您好,这边根据您的描述用上述代码未能复现您的问题,请问您的原始表单中是否已有表格了呢,建议您提供完整 ...

对 原来有表格了 想重写表格的整体样式 就这样了
回复 使用道具 举报
美的人都早起
注册会员   /  发表于:2021-7-19 13:15:10
4#
美的人都早起 发表于 2021-7-19 13:10
对 原来有表格了 想重写表格的整体样式 就这样了

前面绑了表单数据
sheet = this.spread.getSheet(0);
          let that = this;
          sheet.autoGenerateColumns = true;
          sheet.setDataSource(arr);
          sheet.bindColumns(this.columnList);
回复 使用道具 举报
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2021-7-19 13:37:43
5#
美的人都早起 发表于 2021-7-19 13:15
前面绑了表单数据
sheet = this.spread.getSheet(0);
          let that = this;

想修改表格的样式可以先获取表格示例
var table = sheet.tables.all()[0]
然后通过下面的方法修改对应的样式
image.png128432616.png
回复 使用道具 举报
美的人都早起
注册会员   /  发表于:2021-7-19 13:59:22
6#
Derrick.Jiao 发表于 2021-7-19 13:37
想修改表格的样式可以先获取表格示例
var table = sheet.tables.all()[0]
然后通过下面的方法修改对应 ...

let table = sheet.tables.all()[0]

            let thinBorder = new GC.Spread.Sheets.LineBorder("#d3d6db", GC.Spread.Sheets.LineStyle.thin);
            let tableStyleInfo = new GC.Spread.Sheets.Tables.TableStyle("#f5f7fa", "#666", "normal 10pt arial", thinBorder, thinBorder, thinBorder, thinBorder, thinBorder, thinBorder);
            let tableStyle = new GC.Spread.Sheets.Tables.TableTheme();

            tableStyle.name('tableStyle');
            tableStyle.wholeTableStyle(tableStyleInfo);
            table.style(tableStyle);

这样又报别的错了 Cannot read property 'style' of undefined
回复 使用道具 举报
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2021-7-19 14:08:19
7#
美的人都早起 发表于 2021-7-19 13:59
let table = sheet.tables.all()[0]

            let thinBorder = new GC.Spread.Sheets.LineBorder ...

请提供一份完整的demo,这边给您调试吧
回复 使用道具 举报
美的人都早起
注册会员   /  发表于:2021-7-19 14:17:05
8#
Derrick.Jiao 发表于 2021-7-19 14:08
请提供一份完整的demo,这边给您调试吧

let arr=[{
amount: 1
chapter: ""
children: undefined
code: "0101-01-01"
comment: null
contractListId: null
createdAt: "2021-07-19 10:58:55"
createdBy: null
deviceCode: "ff"
deviceName: ""
deviceType: ""
deviceUnit: ""
itemMetaId: 12
measureUnit: ""
name: ""
parentCode: "0101-01"
price: 500
secondCode: ""
section: ""
sumList: null
type: "DEVICE"
updatedAt: "2021-07-19 10:58:55"
updatedBy: null
worth: null
}];
let columnList=[{
{name:'itemMetaId', displayName:'', size:0},
          {name:'code',displayName:'清单标号',size:150,formatter:'0'},
          {name:'secondCode',displayName:'清单编码',size:150,formatter:'0'},
          {name:'chapter',displayName:'章',size:30,formatter:'0'},
          {name:'section',displayName:'节',size:30,formatter:'0'},
          {name:'name',displayName:'名称',size:200,formatter:'0'},
}]
let spread= this.spread
sheet = this.spread.getSheet(0);
let that = this;
sheet.autoGenerateColumns = true;
sheet.setDataSource(arr);
sheet.bindColumns(columnList);
//锁定所有单元格
            let table = sheet.tables.all()[0];
            debugger;

            let thinBorder = new GC.Spread.Sheets.LineBorder("#d3d6db", GC.Spread.Sheets.LineStyle.thin);
            let tableStyleInfo = new GC.Spread.Sheets.Tables.TableStyle("#f5f7fa", "#666", "normal 10pt arial", thinBorder, thinBorder, thinBorder, thinBorder, thinBorder, thinBorder);
            let tableStyle = new GC.Spread.Sheets.Tables.TableTheme();

            tableStyle.name('tableStyle');
            tableStyle.wholeTableStyle(tableStyleInfo);
            table.style(tableStyle);

            sheet.options.protectionOptions = {
              allowSelectLockedCells: true,
              allowSelectUnlockedCells: true,
              allowFilter: true,
              allowSort: true,
              allowResizeRows: true,
              allowResizeColumns: true,
              allowEditObjects: false,
              allowDragInsertRows: false,
              allowDragInsertColumns: false,
              allowInsertRows: false,
              allowInsertColumns: false,
              allowDeleteRows: false,
              allowDeleteColumns: false,
              allowOutlineColumns: false,
              allowOutlineRows: false
            };
            sheet.options.isProtected = true;
回复 使用道具 举报
美的人都早起
注册会员   /  发表于:2021-7-19 14:20:16
9#
美的人都早起 发表于 2021-7-19 14:17
let arr=[{
amount: 1
chapter: ""

let table = sheet.tables.all()[0];
这一步获取的是undefined
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部