Aim to achieve : Want to dump a fetched table to a excel sheet.
My implementation :
Imports System.Data.OleDb
Private Sub getRawDataNextMonth()
Dim sheetName As String = "RawData"
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\rawData.xlsx;Extended Properties=""Excel 12.0 XML;""")
Dim adapter As New Data.OleDb.OleDbDataAdapter("SELECT * FROM [Sheet1$]", con)
Dim dataSet As New Data.DataSet
adapter.Fill(dataSet)
Dim dataTable As Data.DataTable = dataSet.Tables(0)
Dim rawData(dataTable.Rows.Count, dataTable.Columns.Count - 1) As Object
Dim range As Excel.Range = WB.Sheets(sheetName).Range("A2:T" + dataTable.Rows.Count.ToString())
For col = 0 To dataTable.Columns.Count - 1
For row = 0 To dataTable.Rows.Count - 1
rawData(row, col) = dataTable.Rows(row).ItemArray(col)
Next
Next
range.Value2 = rawData
End Sub
I am new to data fetching and ADO.Net concepts and just got it working. But..
This seems to be very inefficient and lame to me.
So, can you help reducing the complexity and may be improve performance ?
A totally different (Better) implementation is most welcome !
Please help me optimize this... with your experience !
This function writes out to a text file as CSV format and then opens the file in Excel and saves it as xlsx format. I tried this with a 53 column x 10,000 row table and it took ~2 seconds: