Fill keyboard shortcut implementation demo

Posted by: davide.vago on 17 May 2021, 5:06 am EST

    • Post Options:
    • Link

    Posted 17 May 2021, 5:06 am EST

    Dear support,

    I’m reaching you out as I was looking at this implementation of a keyboard-driven fill (https://codesandbox.io/s/lucid-raman-1ydsm?file=/src/index.js:1488-1610) and I realised this code can’t be used as the rightFill command.

    I wrote something similar to your snippet but it seems like the filled numbers are increasing by 1 which is not what happens when you right fill via dragging the little cross on the bottom-right corner with the pointer.

    Please check this as reference:

    const rightFill = {
      canUndo: true,
      execute: (wbContext, options, isUndo) => {
        let Commands = GC.Spread.Sheets.Commands
        if (isUndo) {
          Commands.undoTransaction(wbContext, options)
          return true
        } else {
          Commands.startTransaction(wbContext, options)
          wbContext.suspendPaint()
          let selections = wbContext.getActiveSheet().getSelections()
          options.cmd = 'rightFill'
    
          selections.forEach((sel) => {
            let srange = new GC.Spread.Sheets.Range(sel.row, sel.col, sel.rowCount, 1)
            let drange = new GC.Spread.Sheets.Range(sel.row, sel.col + 1, sel.rowCount, sel.colCount - 1)
    
            wbContext.commandManager().execute({
              cmd: 'fill',
              sheetName: wbContext.getActiveSheet().name(),
              startRange: srange,
              fillRange: drange,
              autoFillType: GC.Spread.Sheets.Fill.AutoFillType.fillSeries,
              fillDirection: GC.Spread.Sheets.Fill.FillDirection.right,
            })
          })
          wbContext.resumePaint()
          Commands.endTransaction(wbContext, options)
          return true
        }
      },
    }
    

    Looking forward to hearing from you

  • Posted 18 May 2021, 7:50 am EST

    Hi Davide,

    Thanks for the code snippet. In the code snippet and you have performed the fill with the fillType as fillSeries that is why the numbers are fille as series(incremented with 1). For this, you may change the autoFillType. Please refer to the following code snippet and attached sample that demonstrates the same.

        wbContext.commandManager().execute({
                cmd: "fill",
                sheetName: wbContext.getActiveSheet().name(),
                startRange: srange,
                fillRange: drange,
                autoFillType: GC.Spread.Sheets.Fill.AutoFillType.copyCells,
                fillDirection: GC.Spread.Sheets.Fill.FillDirection.right
              });
    

    sample: https://codesandbox.io/s/youthful-dawn-362cz?file=/src/fillCommands.js:2143-2484

    autoFillType Enum: https://www.grapecity.com/spreadjs/docs/v14/online/SpreadJS~GC.Spread.Sheets.Fill.AutoFillType.html?highlight=autofilltype%2C

    Regards

    Avinash

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels