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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Examples of Programmatic Copy/Paste between two different sheets

Thread ID:

Created:

Updated:

Platform:

Replies:

151327 Feb 7,2020 12:44 AM UTC Feb 10,2020 08:55 AM UTC WinForms 3
loading
Tags: Spreadsheet
Spotty
Asked On February 7, 2020 12:44 AM UTC

I'm trying to cut a range say A1:B4 from spreadsheet1 and Paste this into Say L11:M14 on Spreadsheet2

Using similar code to

            Dim dRange = Spreadsheet1.Workbook.Worksheets(0).Range(1, 1, 4 ,2)
           Spreadsheet1.CopyPaste.Copy(dRange.ConvertExcelRangeToGridRange, False)
        
 
'//This doesnt give me the position to make the paste
            Spreadsheet2.CopyPaste.Paste(dRange, Syncfusion.Windows.Forms.Spreadsheet.PasteOptions.Paste)


Results in problems of throwing the exception on the paste.

{"Unable to cast object of type 'Syncfusion.XlsIO.Implementation.RangeImpl' to type 'Syncfusion.Windows.Forms.CellGrid.GridRangeInfoList'."}

Arulpriya Ramalingam [Syncfusion]
Replied On February 7, 2020 01:22 PM UTC

Hi Spotty, 
 
Thank you for using Syncfusion products. 
 
In order to convert the IRange into GridRangeInfo, the ConvertExcelRangeToGridRange() method of the GridExcelHelper can be used. Please make use of below code to convert the range into GridRangeInfo. 
 
Example code 
 
rangeInfo = new GridRangeInfoList(); 
IRange range = spreadsheet.Workbook.Worksheets[0].Range[2, 2, 2, 7]; 
//To convert the IRange into GridRangeInfo. 
 rangeInfo.Add(GridExcelHelper.ConvertExcelRangeToGridRange(range)); 
//To convert the GridRangeInfo into IRange 
//string iRange = GridExcelHelper.ConvertGridRangeToExcelRange(rangeInfo, spreadsheet.ActiveGrid); 
spreadsheet.CopyPaste.Copy(rangeInfo[0], false); 
 
//To paste the copied content in another sheet. 
spreadsheet.CopyPaste.Paste(rangeInfo, Syncfusion.Windows.Forms.Spreadsheet.PasteOptions.Paste); 
 
Please get back to us, if you have any other queries. 
 
Regards, 
Arulpriya 


Spotty
Replied On February 7, 2020 01:56 PM UTC

So how to specify the paste location.   In my example to location was at a different position.

Arulpriya Ramalingam [Syncfusion]
Replied On February 10, 2020 08:55 AM UTC

Hi Spotty, 
 
Thank you for the update. 
 
As per the Spreadsheet current behavior, the paste operation will be done for the ranges in ActiveGrid. In order to paste values in other sheet programmatically, we would suggest that you to activate the specified sheet to paste the value. Please make use of below code. 
 
Example code 
 
GridRangeInfoList list = new GridRangeInfoList(); 
IRange range = spreadsheet.Workbook.Worksheets[1].Range[4, 5, 4, 11]; 
//To convert the IRange into GridRangeInfo. 
list.Add(GridExcelHelper.ConvertExcelRangeToGridRange(range)); 
string backUpSheet = spreadsheet.ActiveSheet.Name; 
//To change the active grid. 
spreadsheet.SetActiveSheet(range.Worksheet.Name); 
//To paste the copied content in another sheet. 
spreadsheet.CopyPaste.Paste(list, Syncfusion.Windows.Forms.Spreadsheet.PasteOptions.Paste); 
//Revert to the previous sheet, if needed. 
//spreadsheet.SetActiveSheet(backUpSheet); 
 
Please get back to us, if you have any other queries. 
 
Regards, 
Arulpriya 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon