Articles in this section
Category / Section

How to copy a cell value instead of formula in UWP Spreadsheet?

1 min 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,

WPF

WinRT

UWP

 

 

Conclusion

I hope you enjoyed learning about how to copy a cell value instead of formula in Spreadsheet.

You can refer to our UWP Spreadsheet feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.

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 forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied