【发布时间】:2016-04-16 02:25:41
【问题描述】:
以下代码是我当前尝试从 VB.Net 中的网站按钮在 excel 中打开一些数据。我希望数据显示准系统,但网站上表格的格式始终遵循。分页和颜色使数据几乎无法读取,只能看到第一页数据。任何快速修复?我已经尝试了很多我在这里找到的东西,但无济于事。
Private Sub DownloadExcel()
Response.Clear()
'Dim dt As DataTable = TryCast(ViewState("GridData"), DataTable)
Grid_Bad_Meters.AllowPaging = False
Grid_Bad_Meters.AllowSorting = False
'Grid_Bad_Meters.DataSource = dt
'Grid_Bad_Meters.DataBind()
Dim sfile As String = "Communication_Failures" & Now.Ticks
Response.AddHeader("content-disposition", "attachment;filename=" & sfile & ".xls")
Response.Charset = ""
' If you want the option to open the Excel file without saving then
' comment out the line below
' Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel"
Dim stringWrite As New System.IO.StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)
Grid_Bad_Meters.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.End()
'Grid_Bad_Meters.AllowPaging = True
'Grid_Bad_Meters.AllowSorting = True
'GridView1.DataSource = dt
'GridView1.DataBind()
End Sub
【问题讨论】: