Click here to Skip to main content
15,886,077 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Okay here is my running code, I uploaded a .xlsx file,
Sub UploadAndDisplayExcel()
Dim FileName As String = Path.GetFileName(fu_bst.PostedFile.FileName)
Dim Extension As String = Path.GetExtension(fu_bst.PostedFile.FileName)
Dim FilePath As String = Server.MapPath(FolderPath + FileName)

conStr = ConfigurationManager.ConnectionStrings("Excel07ConString").ConnectionString

' "Excel07ConString" - is already configured in my web.config ..

conStr = String.Format(conStr, FilePath, "No")
Dim connExcel As New OleDbConnection(conStr)
Dim cmdExcel As New OleDbCommand()
Dim oda As New OleDbDataAdapter()
Dim dt As New DataTable()
cmdExcel.Connection = connExcel
connExcel.Open()
Dim dtExcelSchema As DataTable
dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
Dim SheetName As String = dtExcelSchema.Rows(0)("TABLE_NAME").ToString()
connExcel.Close()

connExcel.Open()
cmdExcel.CommandText = "SELECT * From [" & SheetName & "]"
oda.SelectCommand = cmdExcel
oda.Fill(dt)
connExcel.Close()

End Sub

Response.Write(ConvertDataTableToHTMLTable(dt)) 'ConvertDataTableToHTMLTable is a function that does convert DataTable to Html Table

and this is the sample excel that i want to upload (it looks like this)



HTML
--------------------------------------------------------------
Preview1 |        |       | Preview2 |       |       | Preview |
--------------------------------------------------------------
Sample   | Data   | Data  | *        |       |       |         |
--------------------------------------------------------------
Data     | Data   | Data  | -        |       |       |         |
--------------------------------------------------------------
Data     | Data   | Data  | -        |       |       |         |
--------------------------------------------------------------


THe * is a Date ..
The - is a computed value, when it has no computation it display "-"
and Data is character, number and formula

when i use the function .. it uploads and display but .. in column Preview2 all "-" changes into #12/30/1899# i dunno why?

Should I my excel file must have value?? can i upload the excat values the excel has? HOW?
Posted
Comments
author.ius 20-Jun-14 3:59am    
As I Tested it with values .. it display now different dates ..but not the actual/exact value

I Think when it first read the date on that column, all data is being read as date?
What do you think?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900