Je dois générer environ 800 fichiers Excel à partir d'une base de données d'accès.lente exportation de l'accès à Excel
Pour les 10-15 premiers, ça marche bien, quelques secondes/fichier Excel mais ça prend toujours plus de temps, au 150ème fichier Excel, ça prend 10 minutes.
Voici mon code:
Il fait cela pour chaque nrliste dans la table d'accès (environ 800 d'entre eux)
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
Voir la réponse modifiée de moi ci-dessous. Merci!! – shahkalpesh