Is it possible to read all items in excel items without using looping ? I have almost 20 thousand rows in my excel it takes too long to put the items in Listview.
This is my current code :
xlWorkBook = xlApp.Workbooks.Open(FileName)
xlWorkSheet = xlWorkBook.Worksheets("ExportedFromDatGrid")
xlApp.Sheets("ExportedFromDatGrid").activate()
xlApp.Range("A2").Activate()
Dim cCount As Integer
Dim azr As Microsoft.Office.Interop.Excel.Range
azr = xlWorkSheet.UsedRange
For cCount = 2 To azr.Rows.Count
Dim newitem As New ListViewItem()
Dim excelvalue As String = (Format(azr.Cells(cCount, 2).value, "yyyy-MM-dd"))
Dim fromdate As String
fromdate = dtpFrom.Value.ToString("yyyy-MM-dd")
Dim todate As String
todate = dtpTo.Value.ToString("yyyy-MM-dd")
'MessageBox.Show(fromdate & "FROM - << TO- >>>>" & todate)
If ((excelvalue >= fromdate) And (excelvalue <= todate)) Then
newitem.Text = "CGC-" & azr.Cells(cCount, 1).value.ToString
newitem.SubItems.Add(Format(azr.Cells(cCount, 2).value, "yyyy-MM-dd HH:mm:00"))
newitem.SubItems.Add(azr.Cells(cCount, 3).value.ToString)
newitem.SubItems.Add(azr.Cells(cCount, 4).value.ToString)
newitem.SubItems.Add(azr.Cells(cCount, 5).value.ToString)
lvAll.Items.Add(newitem)
End If
Next
xlWorkBook.Close()
xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(azr)