Winform Exporting Data to Excel form Datagridview



How can i optimize the perfomance of exporting data from datagridview with
500 rows of data to excel?

I've added reference to Microsoft Excel 11.0 object library.
It's taking 3-4 minutes to export 500 rows.

below is the code, which i wrote:

Excel.ApplicationClass excelApp = new Excel.ApplicationClass();
int ColumnIndex = 0;
foreach (DataGridViewColumn col in dgv.Columns)
excelApp.Cells[1, ColumnIndex] = col.HeaderText;
int rowIndex = 0;
foreach (DataGridViewRow row in dgv.Rows)
//ColumnIndex = 0;
for (int colIndex = 1; colIndex < dgv.Columns.Count;
colIndex++)// (DataGridViewColumn genCol in dgv.Columns)
excelApp.Cells[rowIndex + 1, colIndex] =

Would appriciate any good suggetions or help

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question