我的一个导出EXECL类,你看看吧
Public Class Cexecl
'导出EXECL
Public Sub to_execl(ByVal response As System.Web.HttpResponse, ByVal HttpContext As System.Web.HttpContext, ByVal dgd_list As DataGrid, ByVal filename As String)
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename + ".xls")
response.ContentType = "application/vnd.ms-execl"
HttpContext.Current.Response.Charset = "GB2312"
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default
dgd_list.Page.EnableViewState = False
Dim tw As System.IO.StringWriter = New System.IO.StringWriter
Dim hw As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(tw)
dgd_list.Visible = True
dgd_list.RenderControl(hw)
HttpContext.Current.Response.Write(tw.ToString())
HttpContext.Current.Response.End()
End Sub
Public Sub to_execl_list(ByVal response As System.Web.HttpResponse, ByVal HttpContext As System.Web.HttpContext, ByVal dgd_list As DataList, ByVal filename As String)
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename + ".xls")
response.ContentType = "application/vnd.ms-execl"
HttpContext.Current.Response.Charset = "GB2312"
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default
dgd_list.Page.EnableViewState = False
Dim tw As System.IO.StringWriter = New System.IO.StringWriter
Dim hw As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(tw)
dgd_list.Visible = True
dgd_list.RenderControl(hw)
HttpContext.Current.Response.Write(tw.ToString())
HttpContext.Current.Response.End()
End Sub
End Class