troubleshooting Question

exporting an excel file to a pipe delimited file

Avatar of freds_It
freds_ItFlag for United Kingdom of Great Britain and Northern Ireland asked on
Microsoft ExcelVisual Basic.NET
5 Comments2 Solutions589 ViewsLast Modified:
I'm using this bit of code from a vb.net app, to load an excel worksheet, and convert it to a pipe delimited file.
It's not reading in the first row. What's wrong?
Private Function dostuff() As Boolean
        Dim pram As OleDbParameter
        Dim dr As DataRow
        Dim olecon As OleDbConnection
        Dim olecomm As OleDbCommand
        Dim olecomm1 As OleDbCommand
        Dim oleadpt As OleDbDataAdapter
        Dim ds As DataSet
        Try
            olecon = New OleDbConnection
            olecon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= F:\testing\LIVE091021\maria.xls; Extended Properties=Excel 8.0;"
 
 
            olecomm = New OleDbCommand
            olecomm.CommandText = "Select * from [Sheet1$]"
            olecomm.Connection = olecon
 
            oleadpt = New OleDbDataAdapter(olecomm)
            ds = New DataSet
            olecon.Open()
            oleadpt.Fill(ds, "Sheet1")
            If IsNothing(ds) = False Then
 
                Dim writer As New StreamWriter("F:\LIVE091021\result.ACT", False)
 
                Dim success As Boolean
                
                Dim thisTable As DataTable
                thisTable = ds.Tables(0)
                Dim row As DataRow
                For Each row In thisTable.Rows
                    Dim outputline As String
                    Dim column As DataColumn
                    For Each column In thisTable.Columns
                        Dim columnstr As String
                        If Not IsDBNull(row(column)) Then
                            columnstr = row(column).ToString
                        Else
                            columnstr = ""
                        End If
                        outputline = outputline & columnstr & delimiter
                    Next column
                    writer.WriteLine(outputline)
                    outputline = ""
                Next row
 
                writer.Close()
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            olecon.Close()
            olecon = Nothing
            olecomm = Nothing
            oleadpt = Nothing
            ds = Nothing
            dr = Nothing
            pram = Nothing
        End Try
    End Function
ASKER CERTIFIED SOLUTION
Chandan_Gowda

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros