自己封装的Extjs组件GroupGrid的代码(5) toExcel.aspx

toExcel.aspx 主要是将数据导出到Excel中


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;

public partial class pagination_toExcel : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string ReportName = Request.QueryString["excelTitle"];      
        Response.Charset = "GB2312";
        Response.ContentEncoding = System.Text.Encoding.UTF7;
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(ReportName+".xls", Encoding.UTF8).ToString());
        Response.ContentType = "application/ms-excel";
        this.EnableViewState = false;
        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        string head = @"<html><head><meta http-equiv=Content-Type content=text/html; charset=utf-8><style>td{mso-number-format:\@}</style></head><body>";
        string foot = "</body></html>";
        hw.Write("<table ><tr align=center><td  align=center colspan=10  style=font-size:14pt >" + ReportName + "</td></tr></table><br>");
        GridView gv = new GridView();
        gv.GridLines = GridLines.Both;
        gv.DataSource = ToExcel();
        gv.DataBind();
        gv.RenderControl(hw);
        Response.Write(head + tw.ToString() + foot);
        Response.End();
    }

    public DataTable ToExcel()
    {     
       StringBuilder str=new StringBuilder();
       str.Append("select ")
          .Append(Request.QueryString["excelSql"])
          .Append(" from ")
          .Append(Request.QueryString["tableName"])
          .Append(Request.QueryString["where"] == "null" ? "" : " where " + Request.QueryString["where"])
          .Append(" order by ")
          .Append(Request.QueryString["sort"])
          .Append(" ")
          .Append(Request.QueryString["dir"] == "ASC" ? "ASC" : "DESC");
       return CHY.DbHelperSQL.GetDataTable(str.ToString());
    }


    public override void VerifyRenderingInServerForm(Control control)
    {

    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值