Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
Hello
 
I need an opinion again, I have paged datagridview and I need to export data from either desired page or filtered data, that means more pages to excel or csv or whatever, but fast, cause I have many records. I have done with excel in previous of my posts here and it works but it is very slow, how to speed things up
 
this code works but very very very slow, i fa I need to export say 1000 rows ahhhhh man I can go to dinner , come back and it still isn't finished
 

Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();
 
Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
 
Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
 
 
app.Visible = true;
 
worksheet = workbook.Sheets["Sheet1"];
worksheet = workbook.ActiveSheet;
 
for (int i = 1; i < dg1.Columns.Count + 1; i++)
{
   worksheet.Cells[1, i] = dg1.Columns[i - 1].HeaderText;
}
 
for (int i = 0; i < dg1.Rows.Count - 1; i++)
{
   for (int j = 0; j < dg1.Columns.Count; j++)
   {
      worksheet.Cells[i + 2, j + 1] = dg1.Rows[i].Cells[j].Value.ToString();
   }
}
 
[edit]code block added[/edit]
Posted 17-Nov-12 8:58am
Edited 17-Nov-12 9:05am
Nelek49.3K
v2
Comments
Lacy00 at 19-Nov-12 0:06am
   
If you use Microsoft library, you will get fast reply in msdn forum.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Here is a dataexport library[^] that can export more than 4000 rows to excel, csv, word, pdf, html, xml, MS access, dbf etc. You can give it a try.
  Permalink  
Comments
Lacy00 at 19-Nov-12 1:04am
   
thanks for sharing, this project is really useful, especially exporting data.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 210
1 Richard MacCutchan 100
2 kbrandwijk 90
3 ProgramFOX 80
4 Sandeep Singh Shekhawat 70
0 Sergey Alexandrovich Kryukov 9,050
1 OriginalGriff 8,151
2 CPallini 2,613
3 Richard MacCutchan 2,221
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 18 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100