I want to read data from excel file(2007).
files are in folder, I want to target some cells to pick data from them.
Kindly ! help me out !!

Recommended Answers

All 2 Replies

I use this code to read excel file, but I don't if it works in Excel 2007.

Dim myPath as String
        myPath = Request.MapPath(Request.ApplicationPath) & "\Upload\GCMS\" & FUAttach1.FileName
        Try
            Dim objDS As DataSet = New DataSet
            Dim objCmd As OleDbCommand
            Dim objAdapter As OleDbDataAdapter = New OleDbDataAdapter

            MyConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & myPath & ";Extended Properties=""Excel 8.0;IMEX=1;HDR=YES;""")
            MyConnection.Open()

            'Select the data from Sheet1 of the workbook.
            objCmd = New OleDbCommand("select * from [Sheet1$]", MyConnection)

            objAdapter.SelectCommand = objCmd
            objAdapter.Fill(objDS, "XLData")

            If objDS.Tables("XLData").Rows.Count >= 1 Then
                Dim Tb As DataTable
                Tb = objDS.Tables("XLData")
                Dim Row As DataRow
                For Each Row In Tb.Rows
                    If SetStringValue(Row.ItemArray(0).ToString) = "" Then
                        Exit For
                    End If

                 Next Row
            End If
            MyConnection.Close()
        Catch ex As Exception
        
        End Try

Thanks,

Kusno.

Thanks Kusno for your reply...

I have tried some thing similar to it. I'm a C# fan but that doesn't matter here ... I think I'm having problem because of the excell 2007 release.

Lets hope any one else can help in this...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.