Пример #1
0
    protected void lnkexcel_Click(object sender, EventArgs e)
    {
        if (GrdMis.Rows.Count > 0)
        {
            Response.Clear();
            Response.Buffer = true;
            Response.ClearContent();
            Response.ClearHeaders();
            Response.Charset = "";

            // grdListApplication.Columns.RemoveAt(5);
            string         FileName       = "2013_Summer" + ".xls";
            StringWriter   strwritter     = new StringWriter();
            HtmlTextWriter htmltextwrtter = new HtmlTextWriter(strwritter);
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName);

            GrdMis.GridLines             = GridLines.Both;
            GrdMis.HeaderStyle.Font.Bold = true;
            GrdMis.RenderControl(htmltextwrtter);
            Response.Write(strwritter.ToString());
            Response.End();
        }
    }
Пример #2
0
    protected void btnprint1_Click(object sender, EventArgs e)
    {
        GrdMis.UseAccessibleHeader    = true;
        GrdMis.HeaderRow.TableSection = TableRowSection.TableHeader;
        GrdMis.FooterRow.TableSection = TableRowSection.TableFooter;

        string footer = "Register No. " + lblRegNo.Text + "   Total Pages" + lblTotalPage.Text + "   Punched Pages" + lblPunchedPage.Text + "   Diff" + lblDiff.Text;

        StringWriter   sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);

        GrdMis.RenderControl(hw);
        string        gridHTML = sw.ToString().Replace("\"", "'").Replace(System.Environment.NewLine, "");
        StringBuilder sb       = new StringBuilder();

        //////////////////////////////////////////
        string Head = "Data Entry Report For " + ddlExamSession.SelectedItem.Text + "-" + ddlExamYear.SelectedItem.Text;

        sb.Append("<script type = 'text/javascript'>");
        sb.Append("window.onload = new function(){");
        sb.Append("var printWin = window.open('', '', 'left=0");
        sb.Append("left=100,top=200,right=100,bottom=300,width=700,height=500,status=0');");
        sb.Append("printWin.document.write(\"");
        sb.Append("<html>");
        sb.Append("<head>");
        sb.Append("<style type='text/css'>");
        sb.Append("@media print {" +
                  "thead { display: table-header-group,inline; }" +
                  "}" +
                  //"div.chapter, div.appendix {page-break-after: always;}"+
                  "p{ text-align:center;" + "font-size:large; " +
                  "font-family:'Calibri';" +
                  "color:black;" + "margin-left:120px;}" +
                  ".amr{ text-align:center;" + "font-size:x-large; " +
                  "font-family:'Calibri';" +
                  "color:black;" + "margin-left:105px;}"
                  );
        sb.Append("</style>");
        sb.Append("</head>");
        sb.Append("<body>");
        sb.Append("<table>");
        sb.Append("<thead><tr><td>" +
                  "<div>" +
                  "<table>" +
                  "<tr>" +
                  "<td rowspan='3'>" +
                  "<div>" +
                  "<img class='logo' src='bootstrap-3.3.6-dist/images/logo.png' Width='60px' Height='60px'  />" +                       //Width='50px' Height='50px'
                  "</div>" +
                  "</td>" +

                  "</tr>" +
                  "<tr>" +
                  "<td>" +
                  "<p class='amr'>Sant Gadge Baba Amravati University</p>" +
                  "</td>" +
                  "</tr>" +
                  "<tr>" +
                  "<td>" +
                  "<div>" +

                  "<p>" + Head + "</p>" +
                  "</div>" +
                  "</td>" +
                  "</tr>" +
                  "</table>" +
                  "</div>" +
                  "</td></tr></thead>"
                  );
        sb.Append("<tbody><tr><td>");
        sb.Append(gridHTML);
        sb.Append("</td></tr></tbody>");
        sb.Append("<tfoot><tr><td>" + footer + "</td></tr></tfoot>");
        sb.Append("</table>");
        sb.Append("</body>");
        sb.Append("</html>");

        sb.Append("\");");
        sb.Append("printWin.document.close();");
        sb.Append("printWin.focus();");
        sb.Append("printWin.print();");
        sb.Append("printWin.close();");
        sb.Append("};");
        sb.Append("</script>");
        ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());
        GrdMis.DataBind();
    }