【发布时间】:2017-11-14 18:12:27
【问题描述】:
您好,我正在使用以下方法将数据库导出到 excel
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=" + FileName);
Response.ContentType = "application/vnd.ms-excel";
EnableViewState = false;
Response.Write("<style> TABLE { border:dotted 1px #999; } TH { border:dotted 1px #D5D5D5; text-align:center } TD { border:dotted 1px #D5D5D5; } </style>");
Response.Write("<table>");
Response.Write("<tr>");
Response.Write("<th>Actual Estimated Price</th>");
Response.Write("<th>Aprroved Estimated Price </th>");
Response.Write("<th>Actual Price</th>");
Response.Write("<th>Aprroved Actual Price </th>");
Response.Write("<th>TransactionID </th>");
Response.Write("<th>Created On</th>");
Response.Write("</tr>");
foreach (DataRow dr in dt.Rows)
{
Response.Write("<tr>");
Response.Write("<td>");
Response.Write(String.Format("{0:0.0#}", dr["EstimatedPriceTotal"].ToString()));
Response.Write("</td>");
Response.Write("<td>");
Response.Write(String.Format("{0:0.0#}", dr["ApprovedEstimatedPriceTotal"].ToString()));
Response.Write("</td>");
Response.Write("<td>");
Response.Write(String.Format("{0:0.0#}", dr["ActualPriceTotal"].ToString()));
Response.Write("</td>");
Response.Write("<td>");
Response.Write(String.Format("{0:0.0#}", dr["ApprovedActualPriceTotal"].ToString()));
Response.Write("</td>");
Response.Write("<td>");
Response.Write(dr["TransactionID"].ToString());
Response.Write("</td>");
Response.Write("<td>");
Response.Write(Convert.ToDateTime(dr["CreatedOn"].ToString()));
Response.Write("</td>");
Response.Write("</tr>");
}
Response.Write("</table>");
Response.End();
但我无法以十进制格式导出 Excel 中的实际估计价格、已批准的估计价格
该值为 5 而不是显示为 5.00
如何从c#端将excel的某些列格式化为十进制格式
更新
如何在 EPPPlus 中合并列标题合并
我希望两个标题名称都为
CustomerName
Mitesh Jain
【问题讨论】:
-
开始使用专门的库来创建 Excel 文件,例如 EPPlus。您现在所做的只是创建一个扩展名为 .xls 的 HTML 页面。然后也可以指定数据类型
-
@VDWWD 点击时没有打开链接,我也不想更改代码。有没有最简单的方法?
-
不,因为您创建的不是 xls 而是 html 页面。但是为什么不更改代码。你可以用更少的代码行来做到这一点。您可以将其全部转换为字符串,但会丢失本地化。
-
@VDWWD 你能给我那个代码作为答案吗
标签: c# asp.net excel excel-2010 epplus