I have to generate about 800 excel files from an access database.
For the first 10-15 of them it's working nice, a few seconds/excel file but it's constantly taking longer, at the 150th excel file it's taking 10 minutes.
Here is my code:
It's doing this for each nrliste in the access table (about 800 of them)
Dim lista = From ls In Liste _
Where ls!Concatenare = nrliste(i) _
Select ls
Dim table = lista.CopyToDataTable
Dim DataArr(table.Rows.Count, 30)
For x = 0 To table.Rows.Count - 1
For y = 0 To 30
DataArr(x, y) = table.Rows(x).Item(y)
Next
Next
Dim filetocopy As String
Dim newcopy As String
Dim tempname As String = nrliste(i).ToString
Dim filename As String = "LISTA INV OBI(MF) LA 30.09.2009_" & tempname.Replace("#", "_")
filetocopy = Environment.CurrentDirectory & "\MACHETA.xls"
newcopy = FolderBD.SelectedPath & "\" & filename & ".xls"
If System.IO.File.Exists(newcopy) = True Then
System.IO.File.Delete(newcopy)
System.IO.File.Copy(filetocopy, newcopy)
Else
System.IO.File.Copy(filetocopy, newcopy)
End If
'excel file
Dim xlWBook As Excel.Workbook = xlApp.Workbooks.Open(newcopy)
Dim xlSheet As Excel.Worksheet = CType(xlWBook.Worksheets("Lista inventar OBI de natura MF"), Excel.Worksheet)
'insereaza liniile necesare
For n = 11 To ((lista.Count - 1) + 11)
With xlSheet
.Rows(n).Insert(Excel.XlDirection.xlDown, 1)
End With
Next
'copiaza datele
With xlSheet
.Range(.Cells(11, 1), .Cells(table.Rows.Count + 11, 31)).Value = DataArr
End With