You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.8 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. namespace OT.Web
  8. {
  9. public partial class ExpFile : System.Web.UI.Page
  10. {
  11. protected void Page_Load(object sender, EventArgs e)
  12. {
  13. string strData = Request["Data"];
  14. string strFileName = Request["FileName"];
  15. if (Context.Items["Data"] != null)
  16. {
  17. strData = Context.Items["Data"].ToString();
  18. }
  19. if (Context.Items["FileName"] != null)
  20. {
  21. strFileName = Context.Items["FileName"].ToString();
  22. }
  23. if (Session["Data"] != null)
  24. {
  25. strData = Session["Data"].ToString();
  26. }
  27. if (Session["FileName"] != null)
  28. {
  29. strFileName = Session["FileName"].ToString();
  30. }
  31. HttpContext.Current.Response.Clear();
  32. HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
  33. HttpContext.Current.Response.ContentType = "application/vnd.xls";
  34. HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + strFileName);
  35. HttpContext.Current.Response.AddHeader("mata", "http-equiv=Content-Type content=text/html;charset=utf-8");
  36. //修正匯出後檔案格式問題,例如電話開頭0931變成931,
  37. HttpContext.Current.Response.Write("<style type=text/css>");
  38. HttpContext.Current.Response.Write("td{mso-number-format:\"\\@\";}");
  39. HttpContext.Current.Response.Write("</style>");
  40. HttpContext.Current.Response.Write(strData);
  41. HttpContext.Current.Response.End();
  42. }
  43. }
  44. }