首页 > 代码库 > C#中如何防止Excel做科学计算法转换
C#中如何防止Excel做科学计算法转换
C#中如何防止Excel做科学计算法转换
string style = @"<style>.text{mso-number-format:\@;}</style>";//注意这是样式,不需要修改可直接使用
Response.Clear();
Response.Buffer = true;
Response.Charset = "utf-8";
Response.AppendHeader("Content-Disposition", "attachment;filename=plandetail.xls");
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.GridView2.RenderControl(oHtmlTextWriter);
Response.Output.Write(style);//这里很重要不写到文件里是无法应用样式的。
Response.Output.Write(oStringWriter.ToString());
Response.Flush();
Response.End();
C#中如何防止Excel做科学计算法转换