麻烦您直接复制我的这段代码,绑定到#button1上,一定在同一个文件一直打开的状态下,重复点击#button1- function demo() {
- let sheet = spread.getActiveSheet()
- let targetTable = sheet.tables.findByName('Table_FS_CUR')
- const tableRange = targetTable.range()
- const sRow = tableRange.row
- const sCol = tableRange.col
- const columns = targetTable.toJSON().columns
- const columnList = []
- columns &&
- columns.forEach((col: { id: number; name: string }, index: number) => {
- const tableColumn = new GC.Spread.Sheets.Tables.TableColumn(
- col.id,
- col.name,
- col.name,
- sheet.getFormatter(sRow + 1, sCol + index, GC.Spread.Sheets.SheetArea.viewport),
- )
- columnList.push(tableColumn)
- })
- targetTable.bindColumns(columnList)
- targetTable.allowAutoExpand(true)
- targetTable.autoGenerateColumns(false)
- const tableName = targetTable.name()
- targetTable.bindingPath(`${tableName}Data`)
- const newDataSource = {
- [`${tableName}Data`]: [
- { No: '123123', CompanyName: '1234234', Country: '2324', Currency: '123123', fs01: '11', fi01: '11'},
- { No: '123123', CompanyName: '1234234', Country: '2324', Currency: '123123', fs01: '222', fi01: '22'},
- { No: '123123', CompanyName: '1234234', Country: '2324', Currency: '123123', fs01: '333', fi01: '33'}
- ]
- }
- const source = new GC.Spread.Sheets.Bindings.CellBindingSource(newDataSource)
- sheet.setDataSource(source)
- // const newDataSource2 = {
- // [`${tableName}Data`]: [
- // { No: null, CompanyName: null, Country: null, Currency: null, fs01: null, fi01: null},
- // {},
- // {},
- // ]
- // }
- // const source2 = new GC.Spread.Sheets.Bindings.CellBindingSource(newDataSource2)
- // sheet.setDataSource(source2)
- // const newDataSource3 = {
- // [`${tableName}Data`]: [
- // { No: '123123', CompanyName: '1234234', Country: '2324', Currency: '123123', fs01: '555', fi01: '55'},
- // { No: '123123', CompanyName: '1234234', Country: '2324', Currency: '123123', fs01: '6666', fi01: '66'}
- // ]
- // }
- // const source3 = new GC.Spread.Sheets.Bindings.CellBindingSource(newDataSource3)
- // sheet.setDataSource(source3)
- }
复制代码 |