zoukankan      html  css  js  c++  java
  • (转)导出EXCEL时科学计数法问题

    //1)  文本:vnd.ms-excel.numberformat:@
    //2)  日期:vnd.ms-excel.numberformat:yyyy/mm/dd
    //3)  数字:vnd.ms-excel.numberformat:#,##0.00
    //4)  货币:vnd.ms-excel.numberformat:¥#,##0.00
    //5)  百分比:vnd.ms-excel.numberformat: #0.00%

    HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.Charset = "";
                HttpContext.Current.Response.ContentType = "application/vnd.ms-xls";
                HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(excelname + ".xls"));
                StringBuilder table = new StringBuilder();
                DataTable dt = ds.Tables[0];
                table.Append("<table style='border:1px solid #000000'><tr>");
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    table.Append("<td>");
                    table.Append(dt.Columns[i].Caption.ToString()); //标格的标题
                    table.Append("</td>");
                }
                table.Append("</tr>");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    table.Append("<tr>");
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        table.Append("<td style='vnd.ms-excel.numberformat:@'>");
                        table.Append(dt.Rows[i][j].ToString());
                        table.Append("</td>");
                    }
                    table.Append("</tr>");
                }
                table.Append("</table>");
                return table.ToString();
                HttpContext.Current.Response.Write(table);
                HttpContext.Current.Response.End();
    
  • 相关阅读:
    9-1058. 选择题(20)
    8-素数打表
    7- 插入与归并
    6-爱丁顿数(题意理解)
    5-单身狗(时间和空间的相互选择)
    4-1068. 万绿丛中一点红
    3-1067. 试密码
    2-素数打比表
    21-矩形的嵌套
    maven设置打jar包并引入依赖包
  • 原文地址:https://www.cnblogs.com/JsonShare/p/4872173.html
Copyright © 2011-2022 走看看