How to copy a cell value instead of formula in WPF Spreadsheet?
SfSpreadsheet provides support to copy the values in a formula cell instead of formula by overriding the Copy method of SpreadsheetCopyPaste Class.
In the sample, create a CustomCopyPaste class inherited from SpreadsheetCopyPaste class and override the Copy method like below code example.
C#
public class CustomCopyPaste : SpreadsheetCopyPaste { public SfSpreadsheet spreadSheet { get; set; } public CustomCopyPaste(SfSpreadsheet spread) : base() { spreadSheet = spread; } public override void Copy() { var copyRange = spreadSheet.ActiveGrid.SelectedRanges.ActiveRange; var excelSourceRange = copyRange.ConvertGridRangeToExcelRange(spreadSheet.ActiveGrid); SourceWorkbookRange = spreadSheet.ActiveGrid.Worksheet.Range[excelSourceRange]; CopyClipboard(copyRange); SourceGrid = spreadSheet.ActiveGrid; } public void CopyClipboard(GridRangeInfo copyRange) { var sb = new StringBuilder(); for (int i = copyRange.Top; i <= copyRange.Bottom; i++) { for (int j = copyRange.Left; j <= copyRange.Right; j++) { sb.Append(SourceWorkbookRange[i, j].DisplayText); if (j != copyRange.Right) sb.Append("\t"); } if (i != copyRange.Bottom) sb.Append("\r\n"); } var data = new DataObject(); if (sb.Length == 0) { sb.Append(" "); } data.SetText(sb.ToString()); Clipboard.SetDataObject(data); sb.Clear(); } }
In the above code example, the copied range’s DisplayRange is copied to the Clipboard instead of Value.
Please find the sample link for your reference,
Conclusion
I hope you enjoyed learning about how to copy a cell value instead of formula in Spreadsheet.
You can refer to our WPF Spreadsheet feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF Spreadsheet example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!