菜鸟向高手的提问

xxzjzb1 2009-04-24 12:24:23
导出EXCEL时,身份证号以“科学技术法”显示于EXCEL中,当双击后其值可以全部看到,但是后几位都变成了零,如何导出后身份证号不按科学技术法显示?
我用C#编写的代码,大致如下:
private void Export(string FileType, string FileName)//导出Excel
{
GridView GridView2 = new GridView();
GridView2.DataSource = (DataView)Session["dvlist7"];
GridView2.DataBind();

Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.GetEncoding("GB2312")).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView2.RenderControl(hw);

Response.Write(tw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
Export("application/ms-excel", "基本信息查询.xls");
}
...全文
83 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wwh1991411 2009-04-24
  • 打赏
  • 举报
回复
我好像做过这个
但我现在忘了
不好意思!
陌上花花 2009-04-24
  • 打赏
  • 举报
回复
帮顶下。
lovehongyun 2009-04-24
  • 打赏
  • 举报
回复
http://www.cnblogs.com/liuxiaobo/archive/2008/05/14/1196764.html
看看这个.

或:
Response.Write(tw.ToString().Replace("<td","<td STYLE='MSO-NUMBER-FORMAT:\\@'"));

推荐lz看一下我发你的文章
zhoulehua 2009-04-24
  • 打赏
  • 举报
回复
wuyq11 2009-04-24
  • 打赏
  • 举报
回复
绑定到gridview1的时候:
<td style="vnd.ms-excel.numberformat:@"><%# DataBinder.Eval(Container.DataItem, "") %></td>

格式进行转换
td {mso-style-parent:style0;
mso-number-format:"\@";}
</style>

zhanghw0704 2009-04-24
  • 打赏
  • 举报
回复
顶下
llsen 2009-04-24
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lovehongyun 的回复:]
http://www.cnblogs.com/liuxiaobo/archive/2008/05/14/1196764.html
看看这个.

或:

C# codeResponse.Write(tw.ToString().Replace("<td","<td STYLE='MSO-NUMBER-FORMAT:\\@'"));


推荐lz看一下我发你的文章
[/Quote]

遇到同样问题,帮你up

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧