I have an excel file with two columns. Also in windows form i have 3 textbox and one button. j=Rows k=columns What i want to do is, When i press the button if my textbox1.text= (j,k) then textbox2.text= (j,k+1) and textbox3.text=(j+1,k). I have made it with using interop,
Imports Excel = Microsoft.Office.Interop.Excel
Imports System.Runtime.InteropServices
Public Class Form1
Dim arrayData(,) As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim xl As Excel.Application = New Excel.Application()
Dim workbook As Excel.Workbook = xl.Workbooks.Open("C:\Users\tr100420\Documents\Visual Studio 2010\Projects\ExcelFunction\DB.xlsx")
Dim sheet As Excel.Worksheet = workbook.Sheets(1)
Dim Obj
Dim dataRange As Excel.Range = sheet.Range("A1", "C500")
Dim empNames As Excel.Range = sheet.Range("C1", "C5")
ReDim arrayData(dataRange.Rows.Count, dataRange.Columns.Count)
Dim j, k As Integer
For j = 1 To dataRange.Rows.Count
For k = 1 To dataRange.Columns.Count
arrayData(j - 1, k - 1) = dataRange.Cells(j, k).Value
If TextBox1.Text = Convert.ToString(dataRange.Cells(j, k).Value2) Then
TextBox2.Text = dataRange.Cells(j, k + 1).Value
TextBox3.Text = dataRange.Cells(j + 1, k).Value
End If
Next k
Next j
workbook.Close() : xl.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xl) : xl = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook) : workbook = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet) : sheet = Nothing
But this method is working too much slow. Is there any solutions for the make it faster or if you have another method to connect and read excel could you please share with me... thank you..