12金币
本帖最后由 小弟弟 于 2023-1-3 17:20 编辑
const insertRowsCopyStyle = {
canUndo: true,
name: 'insertRowsCopyStyle',
execute: (context, options, isUndo) => {
const Commands = GC.Spread.Sheets.Commands
if (isUndo) {
Commands.undoTransaction(context, options)
return true
} else {
Commands.startTransaction(context, options)
const sheet = context.getSheetFromName(options.sheetName)
sheet.suspendPaint()
// 先执行原生insertRows命令
options.cmd = 'gc.spread.contextMenu.insertRows'
context.commandManager().execute(options)
options.cmd = 'insertRowsCopyStyle'
let beforeRowCount = 0
if (options.selections && options.selections.length) {
const selections = this.getSortedRowSelections(options.selections)
for (let i = 0; i < selections.length; i++) {
const selection = selections
if (selection.row > 0) {
for (let row = selection.row + beforeRowCount; row < selection.row + beforeRowCount + selection.rowCount; row++) {
sheet.copyTo(selection.row + beforeRowCount - 1, -1, row, -1, 1, -1, GC.Spread.Sheets.CopyToOptions.style | GC.Spread.Sheets.CopyToOptions.span)
}
}
beforeRowCount += selection.rowCount
}
}
sheet.resumePaint()
Commands.endTransaction(context, options)
return true
}
}
}
// 注册命令
spread.commandManager().register('insertRowsCopyStyle', insertRowsCopyStyle)
// 替换原有插入命令
function MyContextMenu() {}
MyContextMenu.prototype = new GC.Spread.Sheets.ContextMenu.ContextMenu(spread)
MyContextMenu.prototype.onOpenMenu = function (menuData, itemsDataForShown, hitInfo, item) {
itemsDataForShown.forEach(function (item, index) {
if (item && item.name === 'gc.spread.insertRows') {
item.command = 'insertRowsCopyStyle'
}
})
}
const contextMenu = new MyContextMenu()
spread.contextMenu = contextMenu
这个要怎么改才能又能往下插入还能复制上面的样式呢
|
|