<asp:LinkButton ID="lnkbtnExport" runat="server" onclick="lnkbtnExport_Click" Visible="false" > <asp:Image ImageUrl="~/Images/excel_icon.gif" ID="downloadExcel" runat="server" /> <asp:Label ID="lblExportExcel" Text="Export To Excel" runat="server" ></asp:Label> </asp:LinkButton>
protected void lnkbtnExport_Click(object sender, EventArgs e) { string Output = lblOutput.Text.ToString(); string fileName = "attachment;filename= DashBoardReportOn_" + DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss") + ".xls"; Response.Clear(); Response.AddHeader("content-disposition", fileName); Response.Charset = ""; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/excel"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); //Table1.RenderControl(htmlWrite); DisplayTbH.RenderControl(htmlWrite); DisplayTb.RenderControl(htmlWrite); StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); Table1.RenderControl(htw); string NewOutput = stringWrite.ToString(); NewOutput = NewOutput.Replace("</table>", ""); NewOutput = NewOutput + Output + "</table>"; Response.Write(NewOutput); Response.Write("</head>"); Response.Write(sw.ToString()); Response.End(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)