Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys

I am currently generating reports in excel through vb.net.

Currently the process that i am using is i get the data from the database and store the data returned into a datatable

i then loop through each record in the datatable and add each column in each record to the excel sheet

Problem is when the report contains large data e.g. 120 000 + records reports take rather long to generate is there a better way to speed up the performance

What I have tried:

dim dt as new datatable("Vehicles")

dt = GetVehicledata()

for each dtrow in dt.rows
xSheet.Cells(RowDataStart, 4).value = DtRow("REGNUM").ToString
xSheet.Cells(RowDataStart, 5).value = DtRow("DRIVER").ToString
xSheet.Cells(RowDataStart, 6).value = DtRow("STARTDATE").ToString
xSheet.Cells(RowDataStart, 7).value = DtRow("STARTTIME").ToString
xSheet.Cells(RowDataStart, 8).value = DtRow("ENDTIME").ToString
next
Posted
Updated 24-Jan-17 7:55am

If you're using Office Interop (set a reference to the Office PIA's) there is nothing you can do to speed it up. Office Interop is notoriously slow.

Your alternative is to generate the Excel file directly using the "OpenXML SDK", or "ClosedXML SDK", or similar.
 
Share this answer
 
Depending on the types of values (if there are any formulas etc) then you could write your data to an array and then paste that to a range.

The array must always be 2d, even if one of those dimensions is only 1 in length; That doesn't matter in your case as you will have a 2d array to paste
 
Share this answer
 
Assuming the code is meaningful, there is a huge saving.
In this code, RowDataStart is a constant, this imply that you can jump directly to last vehicle and write the row in Excel sheet only once.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900