Category / Section
How to copy cell value instead of formula in WinRT Spreadsheet?
2 mins read
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 DisplayText is copied to the Clipboard instead of Value.
Please find the sample link for your reference,