This project has moved. For the latest updates, please go here.

Unreadable content, even though no content is made

Jun 6, 2011 at 1:38 PM


I'm trying to export an excel sheet, from my website.

I copied the example function, but I keep getting unreadable content. If I tell it to open anyway, it opens fine.

I have tried to comment out EVERYTHING, but I still get the message, when opening with Excel 2007.


This is my crippled function:

    private void DumpExcel(DataTable tbl)
        using (ExcelPackage pck = new ExcelPackage())
            //Create the worksheet
            ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Answers");

            //Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
            //ws.Cells["A1"].LoadFromDataTable(tbl, true);

            //Format the header for column 1-3
            //using (ExcelRange rng = ws.Cells["A1:B1"])
            //    rng.Style.Font.Bold = true;
            //    rng.Style.Fill.PatternType = ExcelFillStyle.Solid;                      //Set Pattern for the background to Solid
            //    rng.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(79, 129, 189));  //Set color to dark blue
            //    rng.Style.Font.Color.SetColor(Color.White);

            //Example how to Format Column 1 as numeric 
            //using (ExcelRange col = ws.Cells[2, 1, 2 + tbl.Rows.Count, 1])
            //    col.Style.Numberformat.Format = "#,##0.00";
            //    col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;

            //Write it back to the client
            Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            Response.AddHeader("content-disposition", "attachment;  filename=Answers.xlsx");

Jun 6, 2011 at 1:42 PM

Look at this thread,

Jun 6, 2011 at 1:45 PM
mrxrsd wrote:

Look at this thread,

Thank you sir, you are amazing.