Hi Everyone
Lately, I found the code as to read all file from Excel file as ".xls" from Excel before 2007, but does not work for ".xlsx" Excel 2007, Please, any help for me (new hired database Developer). A great appreciation from me. Thank you all, the code as below (this code from Internet)
TextFilename = Left(TextFilename, Len(TextFilename) - 4)
TextFilename += ".txt"
If File.Exists(TextFilename) Then
File.Delete(TextFilename)
End If
Dim fs As FileStream
Dim sWrtier As StreamWriter
Dim da As Data.OleDb.OleDbDataAdapter
Dim ds As DataSet = Nothing
da = Nothing
sWrtier = Nothing
Try
fs = New FileStream(TextFilename, FileMode.Create, FileAccess.Write)
sWrtier = New StreamWriter(fs)
Dim cnn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data Source=" + FullFileName + ";Extended Properties=""Excel 8.0;HDR=YES;""")
da = New OleDb.OleDbDataAdapter("Select * from [Sheet1$]", cnn)
ds = New DataSet("ExcelFile")
da.Fill(ds)
GridView1.DataSource = ds
GridView1.DataBind()
GridView1.Visible = True
Dim rowIndex As DataRow
Dim colIndex As DataColumn
sWrtier.BaseStream.Seek(0, SeekOrigin.End)
For Each rowIndex In ds.Tables(0).Rows
For Each colIndex In ds.Tables(0).Columns
If rowIndex(colIndex) Is Nothing Then
sWrtier.Write("" + vbTab)
Else
sWrtier.Write(rowIndex(colIndex).ToString + vbTab)
End If
Next
sWrtier.WriteLine()
Next
'closing the file
Catch ex As Exception
Console.Write(ex.Message)
Finally
ds.Dispose()
ds = Nothing
da.Dispose()
da = Nothing
sWrtier.Close()
sWrtier.Dispose()
sWrtier = Nothing
End Try