landreport.aspx.cs

来自「一个土地管理系统」· CS 代码 · 共 59 行

CS
59
字号
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;

public partial class manage_LandReport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bindReport();
        }
    }
    protected void ReportAction_Click(object sender, EventArgs e)
    {
        getReport();
    }
    public override void VerifyRenderingInServerForm(Control control) { return; }
    /// <summary>
    /// 绑定土地信息
    /// </summary>
    void bindReport()
    {
        GridReport.DataSource = LandData.getAllLandInfo();
        GridReport.DataBind();
    }
    /// <summary>
    /// 生成报表
    /// </summary>
    void getReport()
    {
      
       
        HttpContext.Current.Response.Charset = "GB2312";
        HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
        //设置输出流HTTPMIME类型为excel
        HttpContext.Current.Response.ContentType = "application/ms-excel";
        //将HTTP头添加到输出流
        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=LandInfoReport.xls");
        //不保存该控件的视图状态
        GridReport.Page.EnableViewState = false;
        System.IO.StringWriter sw = new System.IO.StringWriter();
        //将文本写入到输出流
        System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
        //将服务器控件的内容输出到HtmlTextWriter对象中
        GridReport.RenderControl(hw);
        //StringWriter.ToString返回包含迄今为止写入到当前 StringWriter 中的字符的字符串
        HttpContext.Current.Response.Write(sw.ToString());
        HttpContext.Current.Response.End();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?