Best method for exporting a DataGridView to Excel

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<P>I have a datagridview(DGV) which contains data based on a user selections from a pre-defined dataset</P>
<P>In point form:</P>
<P><FONT color=#0000ff size=2>User starts program</FONT></P>
<P><FONT color=#0000ff size=2>program builds datatable</FONT></P>
<P><FONT color=#0000ff size=2>user opens file and program read all data from file into the dataset.datatable</FONT></P>
<P><FONT color=#0000ff size=2>user defines the data they want to see</FONT></P>
<P><FONT color=#0000ff size=2>program displays datagrid based on dataset.datatable and user choices. (basically it displays the whole dataset and removes unwanted columnsrecords)</FONT></P>
<P>I want to be able to export the datagrid to excel (not sure which method yet). I have tried the excelexporter component i found somewhere on the msdn forums (it exports the data to look exactly like the datagridview) but its painfully slow. It exports something in the region of 100 records per minute. Most of the time, the datagridview can contain anywhere from 3000-32,000 records. As such, at 100 records per minute, the excel generation can take updwards of 50minutes. Unacceptably slow for the purposes of the program.</P>
<P>What do people recommend as the best method to quickly dump the contents of a datagrid into excel. By quickly, im talking at the speed of about 10,000 records per minute. In all honesty, anything over 5000 records per minute will be fast enough, but the quicker the better!</P>
<P>Is there a way of creating a new dataset.datatable that is built of the contents of the datagridview and then building an excel sheet by connecting to the new dataset?</P>
<P>I would like to be able to export to Excel 2000-2003 at a minimum, but if i can do excel 97 as well it wont hurt.</P>
<P>Any and all suggestions much appreciated.</P>
<P>Cheers</P>
<P>Mc</P>

View the full article
 
Back
Top