首页 > 编程语言 > 详细

C#中如何防止Excel做科学计算法转换

时间:2015-01-07 14:42:57      阅读:285      评论:0      收藏:0      [点我收藏+]

    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做科学计算法转换

原文:http://www.cnblogs.com/jesn/p/4208317.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!