DragDropBlock without clearing format of source range cells

Posted by: nhan.thanh.nguyen on 7 March 2023, 3:30 pm EST

  • Posted 7 March 2023, 3:30 pm EST

    Hi, teams

    As for the title, I want to mention: Do we have any ways to DragDropBlock cells without clearing the format of source cell ranges?

    Thanks and Best Regards,

    Nhan Nguyen

  • Posted 9 March 2023, 4:47 pm EST

    Hello Nhan,

    You can keep the formatting of source cells while performing drag drop operation by following below given steps. First you need to get the dropDrop command object using GC.Spread.Sheets.Commands.dragDrop statement.

    The dragDrop command takes a copy flag in its command options. When this flag is true, drap/drop operation copies the source range instead of cutting(removing) it. This way you can drag drop the source cell range values and then clear the source range without clearing the styling(formatting). You can clear data, style, comment, tags from a cell range using cellRange.clear() method.

    For further understanding, please refer to the code snippet and attached sample.

    // overriding the execute method of dragDrop command
    let oldExecute = dragDropCommand.execute;
    dragDropCommand.execute = function (context, options, isUndo) {
        GC.Spread.Sheets.Commands.startTransaction(context, options);
        if (keepSourceFormatting) {
            options.copy = true;
        // executes the default execute method
        let result = oldExecute.apply(this, [context, options, isUndo]);
        let sheet = context.getSheetFromName(options.sheetName);
        let cellRange = sheet.getRange(options.fromRow, options.fromColumn, options.rowCount, options.columnCount);
        if (!isUndo && result && keepSourceFormatting) {
        GC.Spread.Sheets.Commands.endTransaction(context, options);
        return result;

    Sample: https://jscodemine.grapecity.com/share/3sINKesQJ0WmlgMbteE_EQ/?defaultOpen={"OpenedFileName"%3A["%2Findex.html"%2C"%2Fsrc%2Fapp.js"]%2C"ActiveFile"%3A"%2Fsrc%2Fapp.js"}

    Doc reference

    dragDrop command: https://www.grapecity.com/spreadjs/api/v15/modules/GC.Spread.Sheets.Commands#dragdrop

    cellRange.clear(): https://www.grapecity.com/spreadjs/api/v15/classes/GC.Spread.Sheets.CellRange#clear



Need extra support?

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

Learn More

Forum Channels