This project has moved and is read-only. For the latest updates, please go here.

Problem creating Excel file

May 25, 2011 at 10:11 AM

Hi,

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;
                pck.SaveAs(Response.OutputStream);
                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?

 

Prince

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: http://epplus.codeplex.com/discussions/223843