Response.ClearContent(); Response.AddHeader("content-disposition", "attachment;filename=CandidateList.xls"); Response.AddHeader("Content-Type", "application/vnd.ms-excel"); Response.ContentEncoding = Encoding.Unicode; Response.BinaryWrite(Encoding.Unicode.GetPreamble()); using (StringWriter sw = new StringWriter()) { using (HtmlTextWriter htw = new HtmlTextWriter(sw)) { GridView grid = new GridView(); grid.DataSource = exportcandidateList; grid.DataBind(); string headerTable = @"<Table><tr><td colspan='12'><center>Candidates - " + ddlCenter.SelectedItem.ToString().ToUpper() + " </center></td></tr></Table>"; Response.Write(headerTable); grid.RenderControl(htw); Response.Write(sw.ToString()); } } Response.End();
Can we export password protected excel using crystal report (ASP.NET C#)? No
string path =@"D:\Projects\CP\CP\bin\Debug\aa.xlsx"; FileInfo newFile = new FileInfo(path); DataTable dt = new DataTable(); dt.Columns.Add("Column 1"); dt.Rows.Add("data1"); using (ExcelPackage package = new ExcelPackage(newFile)) { ExcelWorksheet ws = package.Workbook.Worksheets.Add("demo"); ws.Cells["A1"].LoadFromDataTable(dt, false); package.Save("YourPassword"); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)