Link to home
Start Free TrialLog in
Avatar of freds_It
freds_ItFlag for United Kingdom of Great Britain and Northern Ireland

asked on

exporting an excel file to a pipe delimited file

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Chandan_Gowda
Chandan_Gowda
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of freds_It

ASKER

I'm getting error "could not find installable ISAM" if I make that change
The error occurs because this driver is not registered on the Web server, or the Internet Guest account does not have read and execute permissions to this DLL.

To solve this problem, you can do one things
Please follow the below link
http://www.dotnetspider.com/forum/ViewForum.aspx?ForumId=32454 
if there's more than one property in extended properties they need to be enclosed in single quotes. Once I did this the ISAM error went away.

olecon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= F:\\testing\LIVE091021\maria.xls; Extended Properties='Excel 8.0;HDR=NO'"
 
now all working