日期:2014-05-18  浏览次数:20430 次

[求救]gridview导出之后身份证号是科学计数法
gridview导出之后身份证号是科学计数法,显示之后数据最后几位全是0了。找了半天,改不对啊!!
C# code
    private void Export(string FileName)
    {
        Response.Clear();
        Response.Buffer = true;
        Response.Charset = "GB2312";
        Response.ContentEncoding = System.Text.Encoding.UTF7;
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString() + ".xls");
        Response.ContentType = "application/ms-excel";
        this.EnableViewState = false;
        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        GridView1.RenderControl(hw);
        Response.Write(tw.ToString());
        Response.End();
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
    }
    protected void printout_Click(object sender, EventArgs e)
    {
        Export("学生报名信息");
    }
}


------解决方案--------------------
建议楼主把前台和后台的代码全部贴出来
------解决方案--------------------
打开excel模板导出数据'

string style = @"<style> .text { mso-number-format:\@; } </script> "; 
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
Response.Write(style); 

Response.Write(sw.ToString());
Response.End();


public override void VerifyRenderingInServerForm(Control control)

{

}