关于将ACCESS数据导出到EXCEL表的问题

beckham1122 beckham1122 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
public void ToExcel(System.Web.UI.Control ctl) //将数据导出成为EXCEL
{
Response.Clear();
Response.Buffer= true;
Response.Charset="GB2312";
Response.AppendHeader("Content-Disposition","attachment;filename=info.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);

ctl.RenderControl(oHtmlTextWriter);

Response.Write("<meta http-equiv=Content-Type content=text/html;charset=gb2312>");
Response.Write(oStringWriter.ToString());
Response.End();
}
代码如上,导出都没有问题.关键是导出后,只要是字段值由"0"开头的,都被去掉了零.比如分类号字段"060528959" 就会变成"60528959",如何解决这个问题,谢谢
...全文
评论 16
收藏 已收藏
分享
返回顶部
beckham1122
.NET社区 62,272 成员 668,968 内容