[英]Is it possible to read data from an excel file without uploading it to the server in VB.Net?
[英]What is the best way to read from excel file without losing data? Vb.net
从excel文件读取而不丢失数据的最佳方法是什么? Excel工作表使用ADO读取时,其列格式为HH:MM:SS,时间格式已更改为日期并丢失了实际值:
来自excel的示例:
导入到网格视图后:
码:
Try
' Clear the DataGridView and the connection string TextBox
Dim Datatable As New DataTable("Sometable")
' Fill the DataGridView and connection string TextBox
Using connection As New OleDb.OleDbConnection(Super.Excel_GetConnectionString(txtZDCalc_txtPerPath.Text, txtZDCalc_txtPerPath.Tag))
connection.Open()
Using adapter As New OleDb.OleDbDataAdapter("SELECT * FROM [" & cboxZDCalc_Sheet.SelectedItem & "]", connection)
adapter.Fill(Datatable)
End Using
End Using
Super.ZD_GetEmployees(Datatable)
Catch ex As Exception
' Display any errors
MessageBox.Show("[" & ex.[GetType]().Name & "] " & ex.Message & ex.StackTrace)
End Try
为什么在导入时间后失去价值?
听起来好像要显示TimeSpan而不是日期。 Excel将单元格的值存储为日期时间,并使用格式来控制其显示方式。
您要做的是将DataTable中列的数据类型更改为TimeSpan
在这里看看如何执行此操作: 如何更改数据表中数据列的数据类型?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.