您好,您需要先设置绑定路径后设置对应的表格样式信息,最后才绑定数据,这样就不会有问题,我对您的代码进行了修改,您尝试一下:
- console.log(spread.toJSON());
- var sheet = spread.getActiveSheet();
- // 获取样式
- const cellStyle = sheet.getActualStyle(0, 5);
- console.log(cellStyle);
- sheet.setStyle(0, 0, { ...cellStyle, backColor: "red" });
- var spreadNS = GC.Spread.Sheets;
- var data = {
- name: "Jones",
- region: "East",
- sales: [
- {
- orderDate: "1/6/2013",
- item: "Pencil",
- units: 95,
- cost: 1.99,
- isDelivered: true,
- },
- {
- orderDate: "4/1/2013",
- item: "Binder",
- units: 60,
- cost: 4.99,
- isDelivered: false,
- },
- {
- orderDate: "6/8/2013",
- item: "Pen Set",
- units: 16,
- cost: 15.99,
- isDelivered: false,
- },
- ],
- };
- var convert = function (item) {
- return item["cost"] + "$";
- };
- var table = sheet.tables.add("tableSales", 1, 0, 5, 5);
- var tableColumn1 = new spreadNS.Tables.TableColumn(
- 1,
- "orderDate",
- "Order Date",
- "yyyy-mm-dd"
- );
- var tableColumn2 = new spreadNS.Tables.TableColumn(2, "item", "Item");
- var tableColumn3 = new spreadNS.Tables.TableColumn(3, "units", "Units");
- var tableColumn4 = new spreadNS.Tables.TableColumn(
- 4,
- "cost",
- "Cost",
- null,
- null,
- convert
- );
- var tableColumn5 = new spreadNS.Tables.TableColumn(
- 5,
- "isDelivered",
- "Delivered",
- null,
- new spreadNS.CellTypes.ComboBox()
- );
- table.bind(
- [tableColumn1, tableColumn2, tableColumn3, tableColumn4, tableColumn5],
- "sales"
- );
- // 设置样式
- for (let i = 0; i < 6; i++) {
- table.columnLayoutStyle(i, {
- data: sheet.getActualStyle(0, 0),
- });
- }
- table.autoGenerateColumns(false);
- table.bandRows(false);
- // 绑定数据
- sheet.setDataSource(new GC.Spread.Sheets.Bindings.CellBindingSource({sales:data.sales}))
复制代码 |