Posted 1 August 2023, 1:19 pm EST - Updated 1 August 2023, 1:24 pm EST
ClipboardPasteOptions
Posted by: pedro.moraes on 1 August 2023, 1:19 pm EST
-
-
Posted 2 August 2023, 6:19 am EST - Updated 2 August 2023, 6:24 am EST
Hi Pedro,
Currently, we don’t have any option to paste the values and formulas only. We only have 6 options that are defined in ClipboardPasteOptions Enumeration. This behavior completely aligns with the Microsoft Excel.
However, you could create your own custom command, and paste the values and formulas only.
Kindly refer to the following code snippet and the attached sample:
// Create the Paste Values and Formulas Command let pasteValuesAndFormulasCommand = { canUndo: true, execute: function (context, options, isUndo) { var Commands = GC.Spread.Sheets.Commands; options.cmd = "pasteValuesAndFormulasCommand"; if (isUndo) { Commands.undoTransaction(context, options); return true; } else { Commands.startTransaction(context, options); let activeSheet = context.getActiveSheet(); let activeSelections = activeSheet.getSelections()[0]; let fromRange = [new GC.Spread.Sheets.Range(clipboardData.ranges[0].row, clipboardData.ranges[0].col, clipboardData.ranges[0].rowCount, clipboardData.ranges[0].colCount)]; let toRanges = [new GC.Spread.Sheets.Range(activeSelections.row, activeSelections.col, activeSelections.rowCount, activeSelections.colCount)]; spread.suspendEvent(); spread.suspendPaint(); let fromSheet = context.getSheetFromName(clipboardData.sheetName); // Paste the values spread.commandManager().execute({ cmd: "clipboardPaste", sheetName: activeSheet.name(), fromSheet: fromSheet, fromRanges: fromRange, pastedRanges: toRanges, isCutting: false, clipboardText: "", pasteOption: GC.Spread.Sheets.ClipboardPasteOptions.values }); // Paste the Formulas spread.commandManager().execute({ cmd: "clipboardPaste", sheetName: activeSheet.name(), fromSheet: fromSheet, fromRanges: fromRange, pastedRanges: toRanges, isCutting: false, clipboardText: "", pasteOption: GC.Spread.Sheets.ClipboardPasteOptions.formulas }); // Set the Selection activeSheet.setSelection(activeSelections.row, activeSelections.col, clipboardData.ranges[0].rowCount, clipboardData.ranges[0].colCount) spread.resumePaint(); spread.resumeEvent(); Commands.endTransaction(context, options); return true; } } }Kindly let us know if you face any issues.
References:
clipboardPaste command: https://www.grapecity.com/spreadjs/api/v16/modules/GC.Spread.Sheets.Commands#clipboardpaste
register method: https://www.grapecity.com/spreadjs/api/v15/classes/GC.Spread.Commands.CommandManager#register
Extend Context menu: https://www.grapecity.com/spreadjs/demos/features/worksheet/context-menu/extend-context-menu#demo_source_name
Regards,
Ankit

-
Posted 2 August 2023, 9:03 am EST - Updated 2 August 2023, 9:47 am EST
Is there a way to set this as the default command for the sheet? Using ctrl+c and ctrl+v
And how do I add this function to the toolbar?

-
Posted 3 August 2023, 4:45 am EST
Hi,
For Ctrl + C/Ctrl + V, you could override the “paste” command and execute your custom command inside its execute method.
Kindly refer to the following code snippet:
// Override the Paste spread.commandManager()["paste"].execute = function (spread, options, isUndo) { let activeSheet = spread.getActiveSheet(); spread.suspendEvent(); // Execute your custom command spread.commandManager().execute({ cmd: "pasteValuesAndFormulasCommand", sheetName: activeSheet.name(), activeSelection: activeSheet.getSelections()[0], clipboardData: clipboardData }); spread.resumeEvent(); }To insert the command in the Ribbon, add your custom command to the PasteGroup present in the ribbon. Refer to the following code snippet:
// Add to the Paste Options in the Designers' Ribbon defaultConfig.ribbon[0].buttonGroups[1].commandGroup.children[0].children.push("customPaste");References:
DefaultConfig: https://www.grapecity.com/spreadjs/api/designer/modules/GC.Spread.Sheets.Designer#defaultconfig
execute method: https://www.grapecity.com/spreadjs/api/v16/classes/GC.Spread.Commands.CommandManager#execute
setConfig method: https://www.grapecity.com/spreadjs/api/designer/classes/GC.Spread.Sheets.Designer.Designer#setconfig
Designer Customizations: https://www.grapecity.com/spreadjs/docs/spreadjs_designer_component/customizations
Regards,
Ankit

