报表制作

  以下只是简单的实现了下,并没有按三层架构的要求做

 protected void btnDetail_Click(object sender, EventArgs e)
    {
        tb_view.Visible = false;
        if (ReadMeetingDate.Value == "")
        {
            Response.Write("<script>window.alert('未选择时间')</script>");
            return;
        }

        string sql = "SP_TravalOFFList  N'" + ReadMeetingDate.Value + "',N'" + ddl_site.SelectedValue + "'";
        DataSet ds = SQLHelper.ExecuteDataSet(SQLHelper.Conn, CommandType.Text, sql, null);

        if (ds.Tables[0].Rows.Count == 0)
        {
            downloadMes.Visible = true;
            return;
        }
        DataTable dtExport = ds.Tables[0];
        Aspose.Cells.License lic = new Aspose.Cells.License();
        lic.SetLicense("Aspose.Cells.lic");
        Aspose.Cells.Workbook xlsBK = new Aspose.Cells.Workbook();
        Aspose.Cells.Worksheet xlsST = null;

        xlsST = xlsBK.Worksheets[0];
        xlsST.Cells[0, 1].PutValue("部门名称");
        xlsST.Cells[0, 2].PutValue("卡号");
        xlsST.Cells[0, 3].PutValue("姓名");
        xlsST.Cells[0, 4].PutValue("类别");
        xlsST.Cells[0, 5].PutValue("班别");
        xlsST.Cells[0, 6].PutValue("开始时间");
        xlsST.Cells[0, 7].PutValue("结束时间");
        xlsST.Cells[0, 8].PutValue("天数");
        xlsST.Cells[0, 9].PutValue("事由");
        for (int i = 0; i < dtExport.Rows.Count;i++ )
        {

                xlsST.Cells[i + 1, 0].PutValue(i+1);
                xlsST.Cells[i + 1, 1].PutValue(dtExport.Rows[i]["Depart_C"].ToString());
                xlsST.Cells[i + 1, 2].PutValue(dtExport.Rows[i]["EmpyNo1"].ToString());
                xlsST.Cells[i + 1, 3].PutValue(dtExport.Rows[i]["NAME_C"].ToString());
                xlsST.Cells[i + 1, 4].PutValue(dtExport.Rows[i]["KIND_TYPE"].ToString());
                xlsST.Cells[i + 1, 5].PutValue(dtExport.Rows[i]["WorkRule"].ToString());

                xlsST.Cells[i + 1, 6].PutValue(dtExport.Rows[i]["ApplyBeginTime"].ToString());
                xlsST.Cells[i + 1, 7].PutValue(dtExport.Rows[i]["ApplyEndTime"].ToString());
                xlsST.Cells[i + 1, 8].PutValue(dtExport.Rows[i]["DiffDay"].ToString());
                xlsST.Cells[i + 1, 9].PutValue(dtExport.Rows[i]["Bak"].ToString());
        
           

        }
        System.IO.MemoryStream ms = xlsBK.SaveToStream();

        HttpContext.Current.Response.ClearContent();
        HttpContext.Current.Response.ClearHeaders();
        HttpContext.Current.Response.ContentType = "application/x-msexcel";
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=Export" + DateTime.Now.ToString() + ".xls");
        HttpContext.Current.Response.BinaryWrite(ms.ToArray());
        HttpContext.Current.Response.Flush();
        HttpContext.Current.Response.End();
        ms.Close();


    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值