Asp.net导出到Excel:需要在两列的数据中应用Excel格式,即< style> .amt {mso-number-format:\" \\#\\#0\\.00\&quot ;;}< / style> [英] Asp.net Export To Excel: Need to apply Excel formatting in data of two columns that i.e.<style> .amt{mso-number-format:\"\\#\\#0\\.00\";} </style>

查看:92
本文介绍了Asp.net导出到Excel:需要在两列的数据中应用Excel格式,即< style> .amt {mso-number-format:\" \\#\\#0\\.00\&quot ;;}< / style>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void ExporttoExcel(DataTable table)
       {
           filename = "All_OS" + "_" + datepicker.Value.Replace("/", "-").ToString() +".xls";
           HttpContext.Current.Response.Clear();
           HttpContext.Current.Response.ClearContent();
           HttpContext.Current.Response.ClearHeaders();
           HttpContext.Current.Response.Buffer = true;
           HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
           HttpContext.Current.Response.Write(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">");
           HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
           HttpContext.Current.Response.Charset = "utf-8";
           HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");
           HttpContext.Current.Response.Write("<style> .amt{mso-number-format:\"\\#\\#0\\.00\";} </style>");            //sets font
           HttpContext.Current.Response.Write("<font style='font-size:10.0pt; font-family:Calibri;'>");
           HttpContext.Current.Response.Write("<BR><BR><BR>");
           //sets the table border, cell spacing, border color, font of the text, background, foreground, font height
           HttpContext.Current.Response.Write("<Table border='1' bgColor='#ffffff' "
                                              + "borderColor='#000000' cellSpacing='0' cellPadding='0' "
                                              + "style='font-size:10.0pt; font-family:Calibri; background:white;'> <TR>");
           //am getting my grid's column headers
           int columnscount = table.Columns.Count;
           HttpContext.Current.Response.Write("<TR>");
           HttpContext.Current.Response.Write("<Td colspan=23>");
           HttpContext.Current.Response.Write("<font style='font-size:12.0pt; font-family:Calibri;'><CENTER> ");
           HttpContext.Current.Response.Write("All Outstanding " + datepicker.Value.ToString());
           HttpContext.Current.Response.Write(" </CENTER></Font> ");
           HttpContext.Current.Response.Write("</Td>");
           HttpContext.Current.Response.Write("<TR>");
           for (int j = 0; j < columnscount; j++)
           {
                 //write in new column
                   HttpContext.Current.Response.Write("<Td>");
                   //Get column headers  and make it as bold in excel columns
                   HttpContext.Current.Response.Write("");
                   HttpContext.Current.Response.Write(table.Columns[j].ColumnName.ToString());
                   HttpContext.Current.Response.Write("");
                   HttpContext.Current.Response.Write("</Td>");
           }
           HttpContext.Current.Response.Write("</TR>");

           foreach (DataRow row in table.Rows)
           {//write in new row
               HttpContext.Current.Response.Write("<TR>");
               for (int i = 0; i < table.Columns.Count; i++)
               {
                   HttpContext.Current.Response.Write("<Td>");
                   HttpContext.Current.Response.Write(row[i].ToString());
                   HttpContext.Current.Response.Write("</Td>");
               }
               HttpContext.Current.Response.Write("</TR>");
           }

           HttpContext.Current.Response.Write("</Table>");
           HttpContext.Current.Response.Write("</font>");
           HttpContext.Current.Response.Flush();
           HttpContext.Current.Response.End();
       }























Output
Actual Result
50
100
2,100.00
3,450.00

Expected Result
50.00
100.00
2,100.00
3,450.00

推荐答案

这篇关于Asp.net导出到Excel:需要在两列的数据中应用Excel格式,即&lt; style&gt; .amt {mso-number-format:\&quot; \\#\\#0\\.00\&quot ;;}&lt; / style&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆