2
我正在格式化(小数,日期等)的Excel表格中填充数据表。从Excel中填充数据表列作为字符串
我的问题是,列正被格式化为Excel表格,但我需要填充所有列作为字符串,我该怎么做?
我的导入方法:
Private Function upload(filename As String) As DataTable
Dim FilePath__1 As String = "Uploads/"
Try
Dim allowdFile As String() = {".xls", ".xlsx"}
Dim FileExt As String = ".xls"
Dim isValidFile As Boolean = allowdFile.Contains(FileExt)
If Not isValidFile Then
Return Nothing
Else
Dim filePath__2 As String = Server.MapPath(FilePath__1) & filename
Dim con As OleDbConnection = Nothing
If FileExt = ".xls" Then
con = New OleDbConnection((Convert.ToString("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=") & filePath__2) + ";Extended Properties=Excel 8.0;")
ElseIf FileExt = ".xlsx" Then
con = New OleDbConnection((Convert.ToString("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=") & filePath__2) + ";Extended Properties=Excel 12.0;")
End If
con.Open()
Dim dt As DataTable = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
Dim getExcelSheetName As String = dt.Rows(0)("Table_Name").ToString()
Dim ExcelCommand As New OleDbCommand((Convert.ToString("SELECT * FROM [") & getExcelSheetName) + "]", con)
Dim ExcelAdapter As New OleDbDataAdapter(ExcelCommand)
Dim ExcelDataSet As New DataSet()
ExcelAdapter.Fill(ExcelDataSet)
con.Close()
If ExcelDataSet.Tables.Count > 0 Then
Return ExcelDataSet.Tables(0)
Else
Return Nothing
End If
End If
Catch ex As Exception
Return Nothing
End Try
End Function
任何帮助将是很好。
这不起作用 –
有趣的是,没有错误,只是“不工作”? –
你为什么讥讽?不工作我的意思是列仍然是双重的,日期等... –