Problem creating Excel file

May 25, 2011 at 10:11 AM


I'm using EPPlus to export DataSet to Excel. Developing with C#.NET MVC. Here's a code snippet:

            using (ExcelPackage pck = new ExcelPackage())
                foreach (DataTable tbl in dataSet.Tables)
                    ExcelWorksheet ws = pck.Workbook.Worksheets.Add(tbl.TableName);
                    ws.Cells["A1"].LoadFromDataTable(tbl, true);

                HttpResponse Response = System.Web.HttpContext.Current.Response;
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", "attachment;  filename=Sample1.xlsx");

This launches an alert box with garbled text.

Have anyone encounter the same scenario?



May 25, 2011 at 12:25 PM

When do you see an alert box with garbled text? If it was when you tried to open your excel file, try this: