Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void ExporttoExcel(DataTable table, string filename)
- {
- HttpContext.Current.Response.Clear();
- HttpContext.Current.Response.ClearContent();
- HttpContext.Current.Response.ClearHeaders();
- HttpContext.Current.Response.Buffer = true;
- HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
- HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
- HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
- HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=Resultados_Finales.xlsx");
- using (ExcelPackage pack = new ExcelPackage())
- {
- ExcelWorksheet ws = pack.Workbook.Worksheets.Add(filename);
- ws.Cells["A1"].LoadFromDataTable(table, true);
- ws.Cells[ws.Dimension.Address].AutoFitColumns();
- ws.Column(74).Style.Locked = false;
- ws.Column(75).Style.Locked = false;
- ws.Column(88).Style.Locked = false;
- ws.Column(89).Style.Locked = false;
- ws.Column(90).Style.Locked = false;
- ws.Column(91).Style.Locked = false;
- ws.Column(92).Style.Locked = false;
- ws.Column(93).Style.Locked = false;
- ws.Column(94).Style.Locked = false;
- ws.Cells["BV1:BW1"].Style.Locked = true;
- ws.Cells["CJ1:CP1"].Style.Locked = true;
- ws.Protection.IsProtected = true;
- var ms = new System.IO.MemoryStream();
- pack.SaveAs(ms);
- ms.WriteTo(HttpContext.Current.Response.OutputStream);
- }
- HttpContext.Current.Response.Flush();
- HttpContext.Current.Response.End();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement