// 获取表单
var activeSheet = spread.getActiveSheet();
// 数据
// Data
var data = {
name: 'Jones', region: 'East',
sales: [
{ orderDate: '1/6/2013', item: 'Pencil', units: 95, cost: 1.99, isMakeMoney: true },
{ orderDate: '4/1/2013', item: 'Binder', units: 60, cost: 4.99, isMakeMoney: false },
{ orderDate: '6/8/2013', item: 'Pen Set', units: 16, cost: 15.99, isMakeMoney: false }
],
sales1: [
{ orderDate1: '1/6/2013', item1: 'Pencil', units1: 95, cost1: 1.99, isMakeMoney1: true },
{ orderDate1: '4/1/2013', item1: 'Binder', units1: 60, cost1: 4.99, isMakeMoney1: false },
{ orderDate1: '6/8/2013', item1: 'Pen Set', units1: 16, cost1: 15.99, isMakeMoney1: false }
]
};
var convert = function (item) {
return item['cost'] + '$';
}
// Add table
var table = activeSheet.tables.add('tableSales', 0, 0, 4, 4);
var tableColumn1 = new GC.Spread.Sheets.Tables.TableColumn(1, "orderDate", "Order Date", "d/M/yy");
var tableColumn2 = new GC.Spread.Sheets.Tables.TableColumn(2, "item", "Item");
var tableColumn3 = new GC.Spread.Sheets.Tables.TableColumn(3, "units", "Units");
var tableColumn4 = new GC.Spread.Sheets.Tables.TableColumn(4, "cost", "Cost", null, null, convert);
var tableColumn5 = new GC.Spread.Sheets.Tables.TableColumn(5, "isMakeMoney1", "fe IsMakeMoney", null, new GC.Spread.Sheets.CellTypes.CheckBox());
table.autoGenerateColumns(true);
for (var i = 0; i < 5; i++){
activeSheet.setColumnWidth(i, 110.0, GC.Spread.Sheets.SheetArea.viewport);
}
//table.insertColumns(3, 1);
table.expandBoundRows(true);
table.bind([tableColumn1, tableColumn2, tableColumn3, tableColumn4, tableColumn5], 'sales', data);
表格有四列,table.autoGenerateColumns(true); 允许自动添加列,上面的代码运行后第五列没有数据。
|