一个将表格导出为EXCEL文件的问题(为何总出现的源码)
sztj 2005-12-26 04:31:34 HttpContext.Current.Response.Clear()
HttpContext.Current.Response.Buffer = True
HttpContext.Current.Response.Charset = "GB2312"
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename= " & DateTime.Now.ToShortDateString & ".xls")
HttpContext.Current.Response.ContentType = "application/ms-excel"
Dim myCitrad As New System.Globalization.CultureInfo("ZH-CN", True)
Dim oStringWriter As New System.IO.StringWriter(myCitrad)
Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)
Me.rptList.RenderControl(oHtmlTextWriter)
HttpContext.Current.Response.Write(oStringWriter.ToString())
HttpContext.Current.Response.End()
oStringWriter.Close()
oHtmlTextWriter.Close()
执行以上代码后,可以生成excel文件,但是打开excel文件,里面却都是html源码,在哪里出错,如何解决?