您好,我这边使用您提供的代码测试了一下,仍然无法复现出您的问题:
测试代码如下:
- document.querySelector("#button1").addEventListener("click", function () {
- readFile(spread, "./temp/demo (1).sjs", () => {
- let sheet = spread.getActiveSheet();
- let targetTable = sheet.tables.all()[0];
- const tableRange = targetTable.range();
- const sRow = tableRange.row;
- const sCol = tableRange.col;
- console.log(targetTable);
- const columns = targetTable.toJSON().columns;
- const columnList = [];
- columns &&
- columns.forEach((col, index) => {
- 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);
- });
- });
复制代码 |