我的上传Excel文件将如何显示实际数据.. [英] How will my Upload Excel file display the actual data ..

查看:117
本文介绍了我的上传Excel文件将如何显示实际数据..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这是我运行的代码,我上传了一个.xlsx文件,

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 - 已在我的配置中web.config ..



conStr = String.Format(conStr,FilePath,No)

Dim connExcel As New OleDbConnection(conStr )

Dim cmdExcel作为新的OleDbCommand()

Dim oda作为新OleDbDataAdapter()

Dim dt作为新DataTable()

cmdExcel.Connection = connExcel

connExcel.Open()

Dim dtExcelSchema As DataTable

dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid。桌子,没什么)

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是一个将DataTable转换为Html表的函数



这是我要上传的样本excel(看起来像这样)







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)



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





这是一个日期......

- 是一个计算值,当它没有计算时显示 -

和数据是字符,数字和公式



当我使用该功能..它上传并显示但是......在预览2列中所有 - 变为#12/30/1899 #i dunno为什么?



我的excel文件应该有价值吗?我可以上传excel的excat值吗?如何?



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?

推荐答案

这篇关于我的上传Excel文件将如何显示实际数据..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆