// 根据模板行列总数,动态处理数据源
processBindData() {
this.dataSource = JSON.parse(JSON.stringify(data));
delete this.dataSource.test;
let test1, test2, test3, test4
// 实际项目中需要根据模板行列动态判断是否需要分页,本示例中20行,7列
if (data.test.length > 20 && Object.keys(data.test[0]).length > 7) {
test1 = data.test.slice(0, 20);
test1.forEach((item, index) => {
test1[index] = pickByIndex(item, 0, 6)
})
this.dataSource.test1 = test1;
test2 = data.test.slice(0, 9).concat(data.test.slice(20, data.test.length));
test2.forEach((item, index) => {
test2[index] = pickByIndex(item, 0, 6)
})
this.dataSource.test2 = test2;
test3 = data.test.slice(0, 20);
test3.forEach((item, index) => {
test3[index] = Object.assign(pickByIndex(item, 0, 1), pickByIndex(item, 7, 8))
})
this.dataSource.test3 = test3;
test4 = data.test.slice(0, 9).concat(data.test.slice(20, data.test.length));
test4.forEach((item, index) => {
test4[index] = Object.assign(pickByIndex(item, 0, 1), pickByIndex(item, 7, 8))
})
this.dataSource.test4 = test4;
console.log(this.dataSource);
this.templatePagination();
}
// })
},
2. 根据处理好的数据,动态生成新的sheet,动态填充数据
// 根据处理好的数据,动态生成新的sheet,动态填充数据
templatePagination() {
let sheetJSON = this.spread.getSheet(0).toJSON();
for (let i = 1; i < 5; i++) {
if (i == 1) {
this.spread.removeSheet(0)
}
let newSheet = new GC.Spread.Sheets.Worksheet("第" + i + "页");
this.spread.addSheet(this.spread.getSheetCount(), newSheet);
newSheet.fromJSON(sheetJSON);
newSheet.name("第" + i + "页");
newSheet.setValue(1, 6, "共4页,第" + i + "页");
var tableColumns = [],
names = Object.keys(this.dataSource[test${i}][0]),
labels = Object.keys(this.dataSource[test${i}][0]);
var table = newSheet.tables.add(test${i}, 6, 0, this.dataSource[test${i}].length + 1, Object.keys(this.dataSource[test${i}][0]).length);
table.autoGenerateColumns(false);
names.forEach(function (name, index) {
var tableColumn = new GC.Spread.Sheets.Tables.TableColumn();
tableColumn.name(labels[index]);
tableColumn.dataField(name);
tableColumns.push(tableColumn);
});
table.bindColumns(tableColumns);
table.bindingPath(test${i});
table.style(GC.Spread.Sheets.Tables.TableThemes.none);
table.filterButtonVisible(false);
let source = new GC.Spread.Sheets.Bindings.CellBindingSource(this.dataSource);
newSheet.setDataSource(source);
const sRange = new GC.Spread.Sheets.Range(7, 3, 1, 1);
const fRange = new GC.Spread.Sheets.Range(7, 3, this.dataSource[test${i}].length, 1);
newSheet.fillAuto(sRange, fRange, {
fillType: GC.Spread.Sheets.Fill.FillType.auto,
series: GC.Spread.Sheets.Fill.FillSeries.column,
fillDirection: GC.Spread.Sheets.Fill.FillDirection.down,
});
newSheet.options.showZeros = false;
}
},
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.