我想将数据从数据表导出到 excel 文件中
我收到了这个错误
'EmployeeMaster$' is not a valid name. Make sure that it does not include invalid characters or punctuation and that is not too long.
这是我的代码
Response.Clear()
Dim dt_excel As New System.Data.DataTable
Dim attach As String = "attachment; filename=EmployeeMaster.xls"
File.Delete("C:\Users\Julian\Downloads\EmployeeMaster.xls")
conn.connect()
conn.connectExcel()
dt_excel = conn.openReader("Select * from EmployeeMaster")
Response.ClearContent()
Response.AddHeader("content-disposition", attach)
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Dim tab As String = ""
For Each dc As DataColumn In dt_excel.Columns
Response.Write(tab + dc.ColumnName)
tab = vbTab
Next
Response.Write(vbLf)
conn.openReaderExcel("Create Table [EmployeeMaster$] (EmployeeNo varchar(25))") '<- throw error here
For Each dr As DataRow In dt_excel.Rows
tab = ""
conn.openReaderExcel("Insert into [EmployeeMaster$] (EmployeeNo) values ('" & dr.Item("EmployeeNo") & "')")
Response.Write(vbLf)
Next
Response.End()
我一直想知道我的代码有什么问题..有人可以建议我解决这个问题的方法吗?
所有建议/帮助将不胜感激
问候谢赫