|
-
Apr 22nd, 2013, 07:37 AM
#1
Thread Starter
Addicted Member
excel file read query
hi
i have started a topic on this before but can seem to find the post in my profile.
anyway
i have code that read my excel file here is the code
Code:
Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
If Not String.IsNullOrEmpty(txtFileName.Text) Then
Try
btnClose.Enabled = False
Dim OExcelHandler As New ExcelHandler()
Dim ds As DataSet = OExcelHandler.GetDataFromExcel(txtFileName.Text.Trim())
If ds IsNot Nothing Then
dgvExcelData.SelectionMode = DataGridViewSelectionMode.FullRowSelect
dgvExcelData.EditMode = DataGridViewEditMode.EditProgrammatically
dgvExcelData.DataSource = ds.Tables(0)
End If
Catch ex As Exception
Finally
btnClose.Enabled = True
End Try
End If
End Sub
how do i get that code to read a certain worksheet in my workbook. at the moment the code steps through each tab which is fine but i need to get it to look at certain tabs when i click on my radio button and find certain words in the worksheet
anyone and ideas
-
Apr 22nd, 2013, 09:39 AM
#2
Thread Starter
Addicted Member
Re: excel file read query
like im trying it this way but getting an error
Code:
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
If Not String.IsNullOrEmpty(txtFileName.Text) Then
Try
btnClose.Enabled = False
Dim OExcelHandler As New ExcelHandler()
Dim ds As DataSet = OExcelHandler.GetDataFromExcel(txtFileName.Text.Trim())
Dim currentFind As Excel.Range = Nothing
Dim firstFind As Excel.Range = Nothing
Dim Fruits As Excel.Range = Me.Application.Range("A1", "a500")
' You should specify all these parameters every time you call this method,
' since they can be overridden in the user interface.
currentFind = Fruits.Find("Cash at Bank", , _
Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart, _
Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, False)
While Not currentFind Is Nothing
' Keep track of the first range you find.
If firstFind Is Nothing Then
firstFind = currentFind
' If you didn't move to a new range, you are done.
ElseIf currentFind.Address = firstFind.Address Then
Exit While
End If
With currentFind.Font
.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red)
.Bold = True
End With
currentFind = Fruits.FindNext(currentFind)
End While
Catch ex As Exception
Finally
btnClose.Enabled = True
End Try
End If
End Sub
-
Apr 22nd, 2013, 09:57 AM
#3
Re: excel file read query
You might explain things like;
What is "ExcelHandler", "GetDataFromExcel" etc. There are way to many unknowns in your code to provide suggestions. Lastly, when there is an error as you have mentioned it would be wise to indicate exactly what the errror message is.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|