导出Excel的数值不正确
下面是导出代码:
protected void btnOut_Click(object sender, EventArgs e)
{
int i = 1;
string orderType = string.Empty;
DataTable dt = (DataTable)Session[ "pageDataTable "];
StringWriter sw = new StringWriter();
sw.WriteLine( "序号\t开户人\t开户账号\t开户银行 ");
foreach (DataRow dr in dt.Rows)
{
sw.WriteLine(i + "\t " + dr[ "AccountName "].ToString() + "\t " + dr[ "AccountNo "].ToString() + "\t " + dr[ "BankName "].ToString());
i++;
}
BankBind bankBind = new BankBind();
bankBind.update();
sw.Close();
Response.AddHeader( "Content-Disposition ", "attachment; filename=MyExcelFile.xls ");
Response.ContentType = "application/ms-excel ";
Response.ContentEncoding = System.Text.Encoding.GetEncoding( "GB2312 ");
Response.Write(sw);
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
但是dr[ "AccountNo "].ToString()这列 是用科学计数法 后面三位都变成0了 怎么改程序才行啊 不让他显示科学计数法
------解决方案--------------------可参考
http://dotnet.aspx.cc/article/8a4cbf47-b888-4832-3389-ed3a3a3c8aab/read.aspx
例子
http://dotnet.aspx.cc/Exam/OutPutExcel.aspx
------解决方案--------------------try:
Convert.ToDouble(dr[ "AccountNo "]).ToString( "#0.## ");