在click事件中加入:
Protected Sub imgExcel_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgExcel.Click
Response.Clear()
Response.Buffer = True
Response.Charset = "GB2312"
Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls")
'如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码!!!
Response.ContentEncoding = System.Text.Encoding.UTF7
Response.ContentType = "application/ms-excel" '/设置输出文件类型为excel文件。
Dim oStringWriter As New System.IO.StringWriter()
Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)
' turn off paging
grdeap.AllowPaging = False
grdeap.Columns(0).Visible = False
'注意:不是grdeap.databind()
mydatabind()
grdeap.RenderControl(oHtmlTextWriter)
Response.Output.Write(oStringWriter.ToString())
Response.Flush()
Response.End()
Response.Clear()
Response.Buffer = True
Response.Charset = "GB2312"
Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls")
'如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码!!!
Response.ContentEncoding = System.Text.Encoding.UTF7
Response.ContentType = "application/ms-excel" '/设置输出文件类型为excel文件。
Dim oStringWriter As New System.IO.StringWriter()
Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)
' turn off paging
grdeap.AllowPaging = False
grdeap.Columns(0).Visible = False
'注意:不是grdeap.databind()
mydatabind()
grdeap.RenderControl(oHtmlTextWriter)
Response.Output.Write(oStringWriter.ToString())
Response.Flush()
Response.End()
End Sub
版权声明:程序员胖胖胖虎阿 发表于 2022年9月25日 下午1:40。
转载请注明:【Vegas原创】VB.NET版Excel导出(GridView、DataGrid通吃) | 胖虎的工具箱-编程导航
转载请注明:【Vegas原创】VB.NET版Excel导出(GridView、DataGrid通吃) | 胖虎的工具箱-编程导航
相关文章
暂无评论...