We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Interactively Copy a Range from a spreadsheet

Im looking to select a specific range from a spreadsheet and copy the content so that it can be pasted into an Excel sheet

Preferably not show to make the selection visible but to copy it to the clipboard so its ready to paste into excel.

I know the rows/columns of the cells i need to select

3 Replies

AR Arulpriya Ramalingam Syncfusion Team January 24, 2020 08:31 AM UTC

Hi Spotty, 
Thank you using Syncfusion products. 
In order to copy the content in Spreadsheet cells, the Copy() method of CopyPaste property can be used. We already provided a user guide document to achieve this scenario and please make use of below code and UG. 
Example code 
//To perform copy operation for selected ranges 
GridRangeInfo range = spreadsheet.ActiveGrid.SelectedRanges.ActiveRange; 
spreadsheet.CopyPaste.Copy(range, false); 
//To perform Copy operation 
Please get back to us, if you have any other queries. 

SP Spotty January 24, 2020 12:51 PM UTC

This assumes that I have manually selected the range and its active.

What if I want to select a range of cells programmatically but not make this visible to the UI.

The purpose is that I want to take data from the spreadsheet - copy it to another hidden sheet where I manipulate the data into a different format and then select the massaged data to copy to the clipboard.

So I really don't want to make the selection on the original spreadsheet obvious to the user.

KB Kanimozhi Bharathi Syncfusion Team January 27, 2020 09:12 AM UTC

Hi Spotty, 
You can achieve your requirement by making the copied range as GridRangeInfo type and pass it to Copy method of SpreadsheetCopyPaste class. Please find the code example for reference, 
spreadsheet.WorkbookLoaded += Spreadsheet_WorkbookLoaded; 
private void Spreadsheet_WorkbookLoaded(object sender, WorkbookLoadedEventArgs args) 
  var range = GridRangeInfo.Cells(4, 5, 6, 6); //E4:F6 
  spreadsheet.CopyPaste.Copy(range, false); 
Please let me know if you need any clarifications. 
Kanimozhi B 

Live Chat Icon For mobile
Up arrow icon