现在页面中采用了直接到处DataGrid里面的数据生成EXCEL文件,可是就有一列数据出问题:
那一列是记录用户帐号的
比如数据是:3813269980130029194
可是导出来的数据成了:3。81327E+18,就算是展开也跟上面的数据不对了。。
有什么方法可以让数据不变成科学记数法啊。直接导出的时候是正确的帐号

解决方案 »

  1.   

    我用的是下面代码的导出:
    public void ToExcel(System.Web.UI.Control ctl)  //导出成为EXCEL
    {
    //HttpContext.Current.Response.Charset ="GB2312";
    HttpContext.Current.Response.Charset ="";
    HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=baobiao.xls");

    HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.UTF7; 
    HttpContext.Current.Response.ContentType ="application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
    ctl.Page.EnableViewState =false;
    System.IO.StringWriter  tw = new System.IO.StringWriter() ;
    System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter (tw);
    ctl.RenderControl(hw);
    HttpContext.Current.Response.Write(tw.ToString());

    HttpContext.Current.Response.End();
    //HttpContext.Current.Response.Write("<script>window.history.back();</script>");
    }请问怎么修改会避免上面的问题
      

  2.   

    要先把类似3813269980130029194的值转换成string 类型..
      

  3.   

    TO :
    是在DataGrid里面显示的时候就改过来吗?
      

  4.   

    生成记录集的时候就将用户帐号字段的值转换为字符型.
    select convert(varchar(20),account) as account from table
      

  5.   

    给DataBound事件加上以下代码
    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
      foreach (TableCell cell in e.Item.Cells)
      {
        cell.Attributes.Add("style","vnd.ms-excel.numberformat:@");
      }
    }
      

  6.   

    TO :wu896222(WYF) ( ) 
    不行哦导出来还是变成了科学记数法了。。