页面做好一个GridView控件
导出数据库文件并处理好,导入到GridView
导出到EXCEL文档代码:
Response.Clear()
Response.ClearHeaders()
Response.ClearContent()
Response.Buffer = True
Response.HeaderEncoding = Encoding.GetEncoding("gb2312")
Response.ContentType = "application/octet-stream"
Dim min As String = "_555663.xls"
Response.AddHeader("content-disposition", "attachment; filename=" & min)
Response.ContentType = "up/"
'GridView1.Page.EnableViewState = False
Dim sw As StringWriter = New StringWriter
Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
GridView1.RenderControl(htw)
Response.Write(sw.ToString())
Response.Flush()
Response.End()
你好
EXCEL,是有行数限制的,以前的好象是65536行,EXCEL2007可以达到行1048576
打开EXCEL,二维数组赋值到EXCEL
修改DATASET再写回
Private Function XlsToDataTable(strpath As [String]) As DataTable
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Convert.ToString(strpath) & ";" & "Extended Properties=Excel 8.0;"
Dim conn As New OleDbConnection(strConn)
Dim myCommand As New OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn)
Dim dt As New DataTable()
myCommand.Fill(dt)
Return dt
End Function
----------------------------------------------------
Microsoft Team
Mack Juesson
为什么一定要到excel里呢?
直接用access实现就很好啊
如果一定要到excel里,很复杂的,在知道上不可能说清楚。
建议用Access实现比较简单。