Web页中table导出到execl(带模板)
1.将excel另存为html,将其复制到aspx文件中
2.输出格式为excel
InitData(); Response.Clear(); Response.Buffer = true; Response.Charset = "GB2312"; Response.AddHeader("Content-Disposition", "attachment; filename=" + new AutoNumber().GetNumberByTime()+ ".xls");//这样的话,可以设置文件名为中文,且文件名不会乱码。其实就是将汉字转换成UTF8 // 如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码! Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 System.IO.StringWriter oStringWriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter); this.RenderControl(oHtmlTextWriter);//Add the Panel into the output Stream. //this.GridView1.RenderControl(oHtmlTextWriter);//将gridview输出,你也可以类似的写TextBox1.RenderControl... Response.Output.Write(oStringWriter.ToString());//Output the stream. Response.Flush(); Response.End();
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。