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

Copying table to excel via code

I am trying to write an option to export my grid to excel. It is quite a complex grid with covered cells and borders etc. If i do Grid.CutPaste.CopyRange(GridRangeInfo.Table) I get a divide by zero. Grid.CutPaste.CopyRange(GridRangeInfo.Row(3)) Excel gives an error in its paste function Grid.CutPaste.CopyRange(GridRangeInfo.Cell(1,1)) Works. Is there a way for me to dump the grid colours, layout and all into excel? Cheers Steve

1 Reply

AD Administrator Syncfusion Team August 12, 2003 04:07 AM

Currently Essential Grid only supports 2 clipboard formats, an internal GridData format, and a DataFormats.Text format (tab separated text with newlines for rows). So, currently the only format that Excel can use is the text format. This only supports the text copying, and not cell colors, etc. We are working on supporting BIFF formats, so in the future you would be able to copy more than text. Biff support will not be in the upcoming 2.0 release, but should be available shortly thereafter. You can call range.ExpandRange on a range object to make sure it is a cell range so the Copy has a fixed set cesll to work with.
private void button1_Click(object sender, System.EventArgs e)
{
	GridRangeInfo range = GridRangeInfo.Col(1);
	range = range.ExpandRange(1, 1, this.gridDataBoundGrid1.Model.RowCount-1, this.gridDataBoundGrid1.Model.ColCount);
	this.gridDataBoundGrid1.Model.CutPaste.CopyRange(range);
}

Loader.
Live Chat Icon For mobile
Up arrow icon