Esempio n. 1
0
    protected void btnExportToExcel_Click(object sender, EventArgs e)
    {
        try
        {
            Response.Clear();
            Response.AddHeader("content-disposition", "attachment;filename=(" + Session["SYTerm"].ToString().Replace(" ", string.Empty) + ")" + Session["Filename"] + ".xls");
            Response.ContentType = "application/vnd.xls";
            System.IO.StringWriter       stringWrite = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htmlWrite   = new HtmlTextWriter(stringWrite);

            if (GridViewZ.Visible == true)
            {
                GridViewZ.RenderControl(htmlWrite);
            }
            else if (GridViewEE.Visible == true)
            {
                GridViewEE.RenderControl(htmlWrite);
            }
            else if (GridViewFF.Visible == true)
            {
                GridViewFF.RenderControl(htmlWrite);
            }
            else if (GridViewGG.Visible == true)
            {
                GridViewGG.RenderControl(htmlWrite);
            }
            else if (GridViewR.Visible == true)
            {
                GridViewR.RenderControl(htmlWrite);
            }
            else if (GridViewS.Visible == true)
            {
                GridViewS.RenderControl(htmlWrite);
            }
            else if (GridViewX.Visible == true)
            {
                GridViewX.RenderControl(htmlWrite);
            }

            /*
             * else if(GridViewY.Visible == true)
             * {
             *  GridViewY.RenderControl(htmlWrite);
             * }*/

            Response.Write(stringWrite.ToString());
            Response.End();
        }
        catch (Exception ex)
        {
        }
    }
Esempio n. 2
0
    protected void btnExportToPDF_Click(object sender, EventArgs e)
    {
        try
        {
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=(" + Session["SYTerm"].ToString().Replace(" ", string.Empty) + ")" + Session["Filename"] + ".pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter   sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            if (GridViewZ.Visible == true)
            {
                GridViewZ.RenderControl(hw);
            }
            else if (GridViewEE.Visible == true)
            {
                /*GridViewEE.AllowPaging = false;
                 * GridViewEE.DataBind();*/
                GridViewEE.RenderControl(hw);
            }
            else if (GridViewFF.Visible == true)
            {
                GridViewFF.RenderControl(hw);
            }
            else if (GridViewGG.Visible == true)
            {
                GridViewGG.RenderControl(hw);
            }
            else if (GridViewR.Visible == true)
            {
                GridViewR.RenderControl(hw);
            }
            else if (GridViewS.Visible == true)
            {
                GridViewS.RenderControl(hw);
            }
            else if (GridViewX.Visible == true)
            {
                GridViewX.RenderControl(hw);
            }

            /*
             * else if(GridViewY.Visible == true)
             * {
             *  GridViewY.RenderControl(htmlWrite);
             * }*/

            StringReader sr         = new StringReader(sw.ToString());
            Document     pdfDoc     = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
            HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);
            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();
            htmlparser.Parse(sr);
            pdfDoc.Close();
            Response.Write(pdfDoc);
            Response.End();
        }
        catch (Exception ex)
        {
        }
    }