Sub ExcelToCVS()
Dim StrConn As String
Dim DA As New OleDbDataAdapter
Dim DS As New DataSet
Dim DR As OleDbDataReader
Dim Str As String
Dim ColumnCount As Integer
Dim OuterCount As Integer
Dim InnerCount As Integer
Dim RowCount As Integer
StrConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/Sheet1.xls;Extended Properties=Excel 8.0;"
Dim objConn As New OleDbConnection(StrConn)
Try
objConn.Open()
If objConn.State = ConnectionState.Closed Then
Console.Write("Connection cannot be opened")
Else
Console.Write("WelCome")
End If
Catch ex As Exception
Console.Write(ex.ToString)
Exit Sub
End Try
Dim objCmd As New OleDbCommand("Select * from [Sheet1$]", objConn)
objCmd.CommandType = CommandType.Text
Dim ObjStreamWriter As StreamWriter
ObjStreamWriter = New StreamWriter("D:\New.CSV")
Dim Count As Integer
Count = 0
DA.SelectCommand = objCmd
DA.Fill(DS, "XLData")
RowCount = DS.Tables(0).Rows.Count
ColumnCount = DS.Tables(0).Columns.Count
For OuterCount = 0 To RowCount - 1
Str = ""
For InnerCount = 0 To ColumnCount - 1
Str &= DS.Tables(0).Rows(OuterCount).Item(InnerCount) & ","
Next
'Str &= ","
ObjStreamWriter.WriteLine(Str)
ObjStreamWriter.Close()
Dim SW As New StreamWriter("D:\mylog.log")
SW.WriteLine(ex.ToString)
SW.Close()
objCmd.Dispose()
objCmd = Nothing
objConn.Close()
objConn.Dispose()
objConn = Nothing
End Sub
Posted on 10/17/2006 9:25:19 AM by Varma
Posted on 1/11/2007 4:01:57 PM by Rajendra Prasad
Posted on 1/30/2007 11:31:40 AM by DINESH VORA
Posted on 5/10/2007 7:19:18 AM by Pravat
Posted on 5/21/2007 12:24:44 PM by kibrom
Posted on 5/22/2008 1:47:40 PM by Brandon
Posted on 9/17/2008 6:49:06 PM by Sara
Posted on 12/30/2009 9:34:35 AM by chris
Posted on 1/5/2010 6:31:09 AM by Eduardo
Posted on 1/8/2010 5:23:15 PM by Samik
Posted on 2/2/2010 5:06:29 AM by hiren
Posted on 2/8/2010 12:46:59 PM by faizan ahmad
Posted on 3/18/2010 9:02:31 AM by Johan
Posted on 7/2/2010 1:09:40 PM by Jarrod
Posted on 8/31/2010 12:19:44 AM by Lipton
Posted on 8/31/2010 12:23:10 AM by Lipton
Posted on 12/2/2010 8:29:07 AM by Lineberger