asp.net 导出Excel时,解决纯数字字符串变成类似这样的 2.00908E+18 形式的代码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zdhlwt2008/article/details/53691961

1.当导入excel的数据字段有 [24928161122003E8],导入excel后会以科学计数法转换成2.4928161122003E21也就是2.49*10的21次方,这时候需要转换一下格式.


    public override void VerifyRenderingInServerForm(Control control)
    {
    }
    protected void btnexcel_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow dg in this.gvItem.Rows)
        {
            dg.Cells[10].Attributes.Add("style", "vnd.ms-excel.numberformat: @;");//第十一列的字段是[24928161122003E8]需要转换格式.
        }

        Response.Clear();
        Response.Buffer = true;
        Response.Charset = "GB2312";
        Response.AppendHeader("Content-Disposition", "attachment;filename=Message.xls");
        Response.ContentEncoding = System.Text.Encoding.UTF8;
        Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。   
        System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
        this.gvItem.RenderControl(oHtmlTextWriter);
        Response.Output.Write(oStringWriter.ToString());
        Response.Flush();
        Response.End();
    }



展开阅读全文

没有更多推荐了,返回首页