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

Copy grid to clipboard as Excel format

I'm using code from one of your examples to copy a selected range in my grid to the clipboard in Excel format.
I find that this code works fine for a small selected range (say 2 columns * 5 rows) but for anything over this, the Sheet.Range object throws an out of range exception. It seems that the number of rows and columns in the Sheet is not initialized properly? I though that with xlsIO, all valid cell ranges are available, but the sheet only contains the number of rows and columns it needs?

Is there anything wrong with my code that could be causing this problem?

Many thanks for your excellent support

Richard

CopyToExcel.zip

1 Reply

HA haneefm Syncfusion Team June 29, 2007 09:08 PM UTC

Hi Richard,

Before calling the GridCellToExcel method, Try checking the cell bounds range with WorkSheet by using the below code snippet.

[VB.Net]
If sheet.Columns.Length < iRow or sheet.Rows.Length < iColumn Then
gecc.GridCellToExcel(m_Grid.Model, iRow, iColumn, sheet.Range(iRow, iColumn))
''' continue with next rnage using foreach loop here.
EndIf

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon