数据表的值是
斯大林——001 和迈克尔——002。但是生成excel我得到输出为
在生成excel时,“0”不会出现。如何解决这种类型的场景。
代码:
if (dt.Rows.Count > 0)
{
string filename = " ExportedData.xls";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
DataGrid dgGrid = new DataGrid();
dgGrid.DataSource = dt;
dgGrid.DataBind();
dgGrid.RenderControl(hw);
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
this.EnableViewState = false;
Response.Write(tw.ToString());
Response.End();
}