config.commandMap.batchInsertRowContextMenu = {
text: '批量插入',
commandName: 'batchInsertRowContextMenu',
visibleContext: 'ClickRowHeader',
subCommands: [
'batchInsertRows10',
'batchInsertRows50',
'batchInsertRows100'
]
}
config.commandMap.batchInsertRows10 = {
text: '插入 10 行',
commandName: 'batchInsertRows10',
execute: async(context, propertyName, fontItalicChecked) => {
var commandManager = context.Spread.commandManager()
commandManager.execute({ cmd: 'insertRowAndCopyContent', sheetName: context.Spread.getActiveSheet().name(), rowCount: 10 })
}
}
config.commandMap.batchInsertRows50 = {
text: '插入 50 行',
commandName: 'batchInsertRows50',
execute: async(context, propertyName, fontItalicChecked) => {
var commandManager = context.Spread.commandManager()
commandManager.execute({ cmd: 'insertRowAndCopyContent', sheetName: context.Spread.getActiveSheet().name(), rowCount: 50 })
}
}
config.commandMap.batchInsertRows100 = {
text: '插入 100 行',
commandName: 'batchInsertRows100',
execute: async(context, propertyName, fontItalicChecked) => {
var commandManager = context.Spread.commandManager()
commandManager.execute({ cmd: 'insertRowAndCopyContent', sheetName: context.Spread.getActiveSheet().name(), rowCount: 100 })
}
}
config.contextMenu.push('batchInsertRowContextMenu')
const insertRowAndCopyContent = {
canUndo: true,
execute: (context, options, isUndo) => {
const Commands = GC.Spread.Sheets.Commands
options.cmd = 'insertRowAndCopyContent'
if (isUndo) {
Commands.undoTransaction(context, options)
return true
} else {
Commands.startTransaction(context, options)
context.suspendPaint()
context.suspendEvent()
console.log(context, 'context')
console.log(options, 'options')
var sheet = context.getSheetFromName(options.sheetName)
var selections = sheet.getSelections()
for (var i = 0; i < selections.length; i++) {
var row = selections.row
sheet.addRows(row, options.rowCount)
var fromRange = [new GC.Spread.Sheets.Range(row + options.rowCount, 0, 1, sheet.getColumnCount())]
var toRanges = [new GC.Spread.Sheets.Range(row, 0, options.rowCount, sheet.getColumnCount())]
this.workbook.commandManager().execute({ cmd: 'clipboardPaste', sheetName: options.sheetName, fromSheet: sheet, fromRanges: fromRange, pastedRanges: toRanges, isCutting: false, clipboardText: '', pasteOption: GC.Spread.Sheets.ClipboardPasteOptions.formulasAndFormatting })
console.log(this.workbook.commandManager())
}
context.resumeEvent()
context.resumePaint()
Commands.endTransaction(context, options)
this.$emit('sheetChangeLock')
return true
}
}
}
const commandManager = this.workbook.commandManager()
commandManager.register('insertRowAndCopyContent', insertRowAndCopyContent)
console.log(config, 'config')
this.designer.setConfig(config)
|