附件为示例demo,您可以参考下:
核心代码:
- function beforeSetDataSource(sheet, source) {
- sheet.suspendPaint();
- for (let i = 0; i < sheet.tables.all().length; i++) {
- var table = sheet.tables.all()[i];
- var bindingPath = table.bindingPath();
- for (let i in source.xf) {
- if (i == bindingPath) {
- var length = source.xf[i].length;
- var range = table.range()
- if (length > range.rowCount) {
- var rindex = range.row + range.rowCount - 1;
- var rcount = length - range.rowCount + 1;
- sheet.addRows(rindex, rcount)
- break
- }
- if (length < range.rowCount) {
- var rindex = range.row + range.rowCount - 1;
- var rcount = range.rowCount - length - 1;
- sheet.deleteRows(rindex - rcount, rcount)
- break
- }
- }
- }
- }
- sheet.resumePaint()
- }
复制代码
|
|