你好我这里样式表头是通过spread.fromJSON(jsonData);加载的,然后再通过setDataSource加载表内数据,后面我通过手动再列表前面添加固定列,导致spread.fromJSON添加的格式化没起作用,但我把添加固定列的代码注释后,样式就起效了
let cc = table.range().colCount;
activeSheet.addColumns(cc, historyColumns.length);
let width = activeSheet.getColumnWidth(
cc,
GC.Spread.Sheets.SheetArea.viewport
);
let tableColumns: any = [];
// 获取table原有column
for (let c = 0; c < cc; c++) {
let dataField = table.getColumnDataField(c);
let name = table.getColumnName(c);
let tableColumn = new GC.Spread.Sheets.Tables.TableColumn();
tableColumn.name(name);
tableColumn.dataField(dataField);
tableColumns.push(tableColumn);
}
historyColumns.forEach((element) => {
// 添加新的column
let newTableColumn = new GC.Spread.Sheets.Tables.TableColumn();
newTableColumn.name(element.name);
newTableColumn.dataField(element.value);
tableColumns.unshift(newTableColumn);
console.log(tableColumns);
activeSheet.setColumnWidth(0, width,GC.Spread.Sheets.SheetArea.viewpor);
// table新增一列
table.insertColumns(cc - 1, 1, true);
});
上面是手动添加列的,去掉后格式化正常了
|