比如说有个字段是 身份证
但是如果在gridview上面显示的号码都是正确的
但是导入Excel里都变成类似这样数字
身份证号
3.10115E+16
怎么办啊代码如下
    protected void Page_Load(object sender, EventArgs e)
    {
       //提取数据库显示在 gridview2上
       
    } 
   
   
    //写个提出到EXCEL的方法
    private void Export(string FileType, string FileName)
    {
        Response.Charset = "GB2312";
        Response.ContentEncoding = System.Text.Encoding.UTF7;
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).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();
    }    protected void Button1_Click(object sender, EventArgs e)
    {
        Export("application/ms-excel", "个人资料.xls");     
    }    public override void VerifyRenderingInServerForm(Control control)
    {
    }

解决方案 »

  1.   

    哦,科学记数了,要转为字符再写入EXCEL,还有就是在程序里设置excel单元格文本属性。
      

  2.   

    在导出的时候,在你的身份证号码前加'(单引号)就OK了,然后你的身份证号在Excel里就能以字符串的形式显示了
      

  3.   

    //在gridview的每一行绑定事件里把下面这句话加上,并且数出那个身份证是第几列。
    protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
             if (e.Row.RowType == DataControlRowType.DataRow)
            {
                 //比如身份证是第7列
                 e.Row.Cells[7].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
            }
        }