Export to Excel
#region "Function Export in Excel"
protected override void Render(HtmlTextWriter writer)
{
try
{
if (Page != null)
{
if (export)
{
Page.Response.Clear();
Page.Response.Buffer = true;
Page.Response.ContentType = "application/ms-excel";
Page.Response.AddHeader("content-disposition", "attachment; filename=HR Report " + DateTime.Now.ToString("dd/MM/yyyy") + ".xls");
Page.Response.Charset = "UTF-8";
DateTime ct = DateTime.Now;
string currentdate = Convert.ToString(ct);
HttpContext.Current.Response.Write("<b><h1 style='Text-align:left; padding-left:65px; color: #008000; font-weight: bold; font-style: normal; font-size: large'>HR Report</b></h1>");
this.EnableViewState = false;
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
gvReport.AllowPaging = false;
fnBindGrid();
gvReport.RenderControl(htw);
Page.Response.Write(sw.ToString() + "<br/><br/><b>Report Date : " + currentdate + "</b>");
Page.Response.End();
gvReport.AllowPaging = true;
}
}
base.Render(writer);
}
catch (Exception ex)
{
error.errormethod("Export in Excel render function", ex.Message);
}
}
#endregion
No comments:
Post a Comment