46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Web;
|
|||
|
|
|||
|
namespace NGTools.ASHX
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// ExportXls 的摘要说明
|
|||
|
/// </summary>0
|
|||
|
public class ExportXls : IHttpHandler
|
|||
|
{
|
|||
|
|
|||
|
public void ProcessRequest(HttpContext context)
|
|||
|
{
|
|||
|
context.Response.ContentType = "text/plain";
|
|||
|
string sActionType = context.Request.Params.Get("ActionType") == null ? "" : context.Request["ActionType"].Trim();
|
|||
|
if (sActionType.Equals("EasyUIDataGridToExcle"))
|
|||
|
{
|
|||
|
#region 將EasyUI的DataGrid中的數據 導出Excle
|
|||
|
context.Response.Clear();
|
|||
|
context.Response.Buffer = true;
|
|||
|
context.Response.Charset = "utf-8";
|
|||
|
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
|||
|
context.Response.AppendHeader("content-disposition", "attachment;filename=\"" + HttpUtility.HtmlEncode(context.Request["txtName"] ?? DateTime.Now.ToString("yyyyMMdd")) + ".xls\"");
|
|||
|
context.Response.ContentType = "Application/ms-excel";
|
|||
|
context.Response.Write("<html>\n<head>\n");
|
|||
|
context.Response.Write("<style type=\"text/css\">\n.pb{font-size:13px;border-collapse:collapse;} " +
|
|||
|
"\n.pb th{font-weight:bold;text-align:center;border:0.5pt solid windowtext;padding:2px;} " +
|
|||
|
"\n.pb td{border:0.5pt solid windowtext;padding:2px;}\n</style>\n</head>\n");
|
|||
|
context.Response.Write("<body>\n" + context.Request["txtContent"] + "\n</body>\n</html>");
|
|||
|
context.Response.Flush();
|
|||
|
context.Response.End();
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public bool IsReusable
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|