Last post Dec 27, 2019 01:36 PM by AddWeb Solution
Member
293 Points
676 Posts
Dec 27, 2019 10:32 AM|Gopi.MCA|LINK
Hello
This is my export to excel code
Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=Month_Wise.xls"); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; using (StringWriter sw = new StringWriter()) { HtmlTextWriter hw = new HtmlTextWriter(sw); //To Export all pages GridView1.DataSource = Session["KJBG"]; GridView1.DataBind(); GridView1.RenderControl(hw); //style to format numbers to string string style = @"<style> .grid-sltrow { background: #ddd; font-weight: bold; } .SubTotalRowStyle { border: solid 1px Black; background-color: #F7D47D; font-weight: bold; } .GrandTotalRowStyle { border: solid 1px Gray; background-color: #000000; color: #ffffff; font-weight: bold; } .GroupHeaderStyle { border: solid 1px Black; background-color: #4A766E; color: #ffffff; font-weight: bold; } .serh-grid { width: 85%; border: 1px solid #6AB5FF; background: #fff; line-height: 14px; font-size: 11px; font-family: Verdana; } </style>"; Response.Write(style); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); }
I want to add one row in excel "Report Generated On Today's Date 27-Dec-2019"
How To Add This in above code
Thanking You
Participant
850 Points
492 Posts
Dec 27, 2019 11:22 AM|AddWeb Solution|LINK
Hello Gopi.MCA,
The code added for the Add Header Row Export To Excel
.cs page
Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", "attachment; filename=Month_Wise.xls;"); StringWriter stringWrite = new StringWriter(); string headerTable = @"<Table><tr><td>Report Header</td></tr><tr><td><font style='color: #e6a5fa;'><b> <u>Report Generated On 2019-12-27 </u></b></font></td></tr></Table>"; Response.Write(headerTable); Response.Write(stringWrite.ToString()); Response.End();
You can also apply inline css.
If you still facing issue, then please share your code.
Thanks.
Dec 27, 2019 11:28 AM|Gopi.MCA|LINK
Thanks For Your Reply
How to Add current Date & Time
Dec 27, 2019 01:36 PM|AddWeb Solution|LINK
To add current Date & Time into header you have to just below line that we had attached.
string headerTable = @"<Table><tr><td>Report Header</td></tr><tr><td><font style='color: #e6a5fa;'><b> <u>Report Generated On "+ System.DateTime.Now.ToString("dd-MMM-yyyy hh:mm:ss tt") +"</u></b></font></td></tr></Table>";
If you found any issue please let us know.
Member
293 Points
676 Posts
Add Header Row Export To Excel
Dec 27, 2019 10:32 AM|Gopi.MCA|LINK
Hello
This is my export to excel code
I want to add one row in excel "Report Generated On Today's Date 27-Dec-2019"
How To Add This in above code
Thanking You
Participant
850 Points
492 Posts
Re: Add Header Row Export To Excel
Dec 27, 2019 11:22 AM|AddWeb Solution|LINK
Hello Gopi.MCA,
The code added for the Add Header Row Export To Excel
.cs page
You can also apply inline css.
If you still facing issue, then please share your code.
Thanks.
Member
293 Points
676 Posts
Re: Add Header Row Export To Excel
Dec 27, 2019 11:28 AM|Gopi.MCA|LINK
Hello
Thanks For Your Reply
How to Add current Date & Time
Thanking You
Participant
850 Points
492 Posts
Re: Add Header Row Export To Excel
Dec 27, 2019 01:36 PM|AddWeb Solution|LINK
Hello Gopi.MCA,
To add current Date & Time into header you have to just below line that we had attached.
If you found any issue please let us know.
Thanks.