Example #1
0
        /// <summary>
        /// 导出影院广告情况统计报表
        /// </summary>
        /// <param name="cinema"></param>
        /// <param name="begin"></param>
        /// <param name="end"></param>
        public void AdvList_output(string cinema, string begin, string end)
        {
            DaAdvListItem dal = new DaAdvListItem();
            DataTable dt = dal.getDataTable(cinema, begin, end);

            if (dt.Rows.Count > 0)
            {
                string filename = "myAdvList.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();
        }