datagrid导出到excel时,如果有字符串都是数字,并且第1位是0,那么那个0在excel就不显示出来了,这个该怎么解决呢?
我用的代码。
public void ToExcel(System.Web.UI.Control ctl)
{
Response.Clear();
Response.Buffer= true;
HttpContext.Current.Response.Charset ="utf-8";
HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=Report.xls");
HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.GetEncoding("utf-8");
HttpContext.Current.Response.ContentType ="application/ms-excel"; //image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
ctl.Page.EnableViewState =false;
System.IO.StringWriter tw = new System.IO.StringWriter() ;
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter (tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}