asp.net 如何将datatable作为数据源导出excel文件

2024-11-01 08:24:22
推荐回答(2个)
回答(1):

你绑定的时候 直接把“NewsID,NewsTItle,CreateTime在EXCEL显示为相应的中文标题 新闻ID,新闻标题,发表时间 ” 设定好 直接导出到EXCEL就行

参考代码
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=file.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.这里写你的表格控件名.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();

回答(2):

卓正软件的pageoffice还是跨浏览器的,你参考下吧