1. public static void excelbase()
  2. {
  3. string filename = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Second.ToString() + System.DateTime.Now.Millisecond.ToString() + ".xls";
  4. try
  5. {
  6. string style = @"<style> td { mso-number-format:\@; } </style>";
  7. HttpContext.Current.Response.Clear();
  8. HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename + "");
  9. HttpContext.Current.Response.ContentType = "application/ms-excel";
  10. HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF7;
  11. // Response.Charset = "utf-8";
  12. // Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
  13. System.IO.StringWriter stringWrite = new System.IO.StringWriter();
  14. System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
  15. stringWrite.WriteLine(style);
  16. // gvAsset.RenderControl(htmlWrite);
  17. HttpContext.Current.Response.Write(stringWrite.ToString());
  18. HttpContext.Current.Response.End();
  19. }
  20. catch (Exception ex)
  21. {
  22. // throw new Exception(ex.Message.ToString());
  23. }
  24. }

 

版权声明:本文为cnxinwa原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/cnxinwa/p/3459920.html