Ejemplo n.º 1
0
        /// <summary>
        /// 导出到账情况
        /// </summary>
        /// <param name="contract"></param>
        /// <param name="channel"></param>
        /// <param name="begin"></param>
        /// <param name="end"></param>
        /// <param name="person"></param>
        /// <param name="type"></param>
        public void PayList_output(string contract, string channel, string begin, string end, string person, string type)
        {
            DaPayList dal = new DaPayList();
            DataTable dt = dal.getDataTable(contract, channel, begin, end, person, Convert.ToInt32(type), BaseHelper.getCookie().id.ToString());

            if (dt.Rows.Count > 0)
            {
                string filename = "myPayList.xls";
                System.IO.StringWriter tw = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
                DataGrid dgGrid = new DataGrid();
                dgGrid.DataSource = dt;
                dgGrid.DataBind();

                //Get the HTML for the control.
                dgGrid.RenderControl(hw);
                //Write the HTML back to the browser.
                //Response.ContentType = application/vnd.ms-excel;
                Response.ContentType = "application/vnd.ms-excel";
                Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
                Response.Write(tw.ToString());
            }
            else
            {
                Response.Write("无数据可导出!");
            }

            Response.End();
        }