本帖最后由 Richard.Huang 于 2023-11-15 09:32 编辑
产品:SpreadJS
版本:V16
官方的例子
插入复制上一行并优化性能 < 复制粘贴 < 常见问题 | 葡萄城 SpreadJS 表格控件在线文档 (grapecity.com.cn)
使用的是粘贴命令实现
说copyTo的性能没有这个好,但是我自己写了例子
有背景色的都是有公式的, 公式是往后加列的合计
然后同样复制2000行
代码:
- addRowsProcesser2(activeRow, addRowCount = 1, sheetOrName) {
- console.time('addRowsProcesser2')
- const sheet = this.getSheet(sheetOrName)
- // const sheetName = sheet.name()
- // const setRow = activeRow + 1
- this.stopSpreadRender()
- // sheet.addRows(row + 1, rowCount);
- // 用命令去插入行
- var commandManager = this.spread.commandManager()
- // const CopyToOptions = this.GC.Spread.Sheets.CopyToOptions
- commandManager.execute({ cmd: 'gc.spread.contextMenu.insertRows', sheetName: sheet.name(), selections: [new this.GC.Spread.Sheets.Range(activeRow + 1, -1, addRowCount, -1)] })
- this.spread.suspendEvent()
- const colCount = sheet.getColumnCount()
- const fromRanges = sheet.getRange(activeRow, 0, 1, colCount)
- const pastedRange = sheet.getRange(activeRow + 1, 0, addRowCount, colCount)
- // pastedRange.locked(false)
- this.spread.commandManager().execute({
- cmd: 'clipboardPaste',
- sheetName: sheet.name(),
- fromSheet: sheet,
- fromRanges: [fromRanges],
- pastedRanges: [pastedRange],
- isCutting: false,
- clipboardText: '',
- pasteOption: this.GC.Spread.Sheets.ClipboardPasteOptions.formulasAndFormatting
- })
- console.timeEnd('addRowsProcesser2')
- this.spread.resumeEvent()
- this.resumeSpreadRender()
- },
- /**
- * 新增行的时候
- * @param {*} activeRow 当前点击的行的index,
- * @param {number} addRowCount 默认为1,表示需要增加的行数
- * 往下插入一行
- */
- addRowsProcesser(activeRow, addRowCount = 1, sheet) {
- console.time('addRowsProcesser')
- sheet = sheet || this.spread.getActiveSheet()
- // const sheetName = sheet.name()
- // const setRow = activeRow + 1
- this.stopSpreadRender()
- // sheet.addRows(row + 1, rowCount);
- // 用命令去插入行
- var commandManager = this.spread.commandManager()
- console.time('addRowsProcesser-add')
- commandManager.execute({ cmd: 'gc.spread.contextMenu.insertRows', sheetName: sheet.name(), selections: [new this.GC.Spread.Sheets.Range(activeRow + 1, -1, addRowCount, -1)] })
- console.timeEnd('addRowsProcesser-add')
- this.spread.suspendEvent()
- const CopyToOptions = this.GC.Spread.Sheets.CopyToOptions
- for (let i = activeRow; i < addRowCount + activeRow; i++) {
- /**
- * 除了value其他的选项都要
- * 选项参看:https://gcdn.grapecity.com.cn/showtopic-139328-1-1.html
- */
- // sheet.copyTo(i, -1, i + 1, -1, 1, -1, this.GC.Spread.Sheets.CopyToOptions.all - this.GC.Spread.Sheets.CopyToOptions.value - this.GC.Spread.Sheets.CopyToOptions.span)
- sheet.copyTo(i, -1, i + 1, -1, 1, -1, CopyToOptions.formula | CopyToOptions.style)
- }
- console.timeEnd('addRowsProcesser')
- this.spread.resumeEvent()
- this.resumeSpreadRender()
- },
复制代码 clipboardPaste的方式并没有比copyTo的快
|
-
|