Hi all,
I recently have been working on developing a CRM for my wife's beauty center, using VB.NET and managing data via Excel files.
All works fine, i could implement all functionalities, but the operations are way too slow... in order to open the weekly calendar it takes up to 10-12 seconds with 1 appointment per day in the week... to load the contact list (200 records) and show them in a datagridview it takes around 30-35 secs.
I was wondering if there is a way to make the operations quicker...
The typical VB/Excel interaction happens with this kind of structure:
Code:Imports Microsoft.Office.Interop.Excel Imports System.Data Public Class Form1 Private Sub LoadExcelData(filePath As String) Dim excelApp As New Application() Dim excelWorkbook As Workbook = excelApp.Workbooks.Open(filePath) Dim excelWorksheet As Worksheet = CType(excelWorkbook.Sheets(1), Worksheet) Dim range As Range = excelWorksheet.UsedRange Dim dt As New DataTable() dt.Columns.Add("client_name") dt.Columns.Add("birthdate_registration_date") dt.Columns.Add("init_height") dt.Columns.Add("init_weight") dt.Columns.Add("level") dt.Columns.Add("score") dt.Columns.Add("location") For i As Integer = 2 To range.Rows.Count Dim row As DataRow = dt.NewRow() row("client_name") = CType(range.Cells(i, 1), Range).Value row("birthdate_registration_date") = CType(range.Cells(i, 2), Range).Value row("init_height") = CType(range.Cells(i, 3), Range).Value row("init_weight") = CType(range.Cells(i, 4), Range).Value row("level") = CType(range.Cells(i, 5), Range).Value row("score") = CType(range.Cells(i, 6), Range).Value row("location") = CType(range.Cells(i, 7), Range).Value dt.Rows.Add(row) Next DataGridView1.DataSource = dt excelWorkbook.Close(False) excelApp.Quit() ReleaseObject(excelWorksheet) ReleaseObject(excelWorkbook) ReleaseObject(excelApp) End Sub Private Sub ReleaseObject(ByVal obj As Object) Try System.Runtime.InteropServices.Marshal.ReleaseComObject(obj) obj = Nothing Catch ex As Exception obj = Nothing Finally GC.Collect() End Try End Sub End Class




Reply With Quote
