行动结果:
var strLawTable = new StringBuilder();
strLawTable.Append("<thead>");
strLawTable.Append("<tr>");
strLawTable.Append("<th style=\"text-align: right\">Dollar</th>");
strLawTable.Append("</tr>");
strLawTable.Append("</thead>");
strLawTable.Append("<tbody>");
foreach (Currency currency in Model.List)
{
strLawTable.Append("<tr>");
strLawTable.Append("<th style=\"text-align: right\">=\"" + GetExcellFormatString(Currency.USD) + "\"</th>");
strLawTable.Append("</tr>");
}
strLawTable.Append("</tbody>");
string headerTable = "<table>" + strLawTable + "</table>";
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=TestFile.xls");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.Unicode;
Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
System.IO.StringWriter sw = new System.IO.StringWriter();
sw.Write(headerTable);
System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(sw);
Response.Write(sw.ToString());
Response.End();
GetExcellFormatString
method:
public string GetExcellFormatString(double doubleAmount)
{
if (doubleAmount < 1000)
return doubleAmount.ToString("0.00");
else if (doubleAmount < 1000000)
return doubleAmount.ToString("0000.00");
else if (doubleAmount < 1000000000)
return doubleAmount.ToString("0000,000.00");
else if (doubleAmount < 1000000000000)
return doubleAmount.ToString("0000000000.00");
else return doubleAmount.ToString();
}
我的问题:
将数据导出到 Excel 文件后,下面的 Excel 表中有值,
导出的 Excel 表格
Dollar
50.0
35.0
40.0
60.0
etc..
If I press to "ctrl" and click使用鼠标 35.0 和 40.0 Excel不能将 35.0 和 40.0 相加因为35.0 是字符串显示“35.0”,40.0 是字符串显示“40.0”.
问题是关于所选行的总和,但我无法求和,因为值是字符串而不是数字
我怎样才能删除" "C# 代码在 Excel 表中超出字符串编号?
Thanks.
要删除引号,请更改此行:
strLawTable.Append("<th style=\"text-align: right\">=\"" + GetExcellFormatString(Currency.USD) + "\"</th>");
^^remove ^^remove
to this:
strLawTable.Append("<th style=\"text-align: right\">=" + GetExcellFormatString(Currency.USD) + "</th>");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)