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

Getting excel error "found unreadable content" ..

Jul 14, 2011 at 6:01 PM


I keep getting the error "there was found unreadable content ......." error.
I tried with "response.clear()" and also downloaded the latest source and compiled it in, but no dice .....


protected void cmb_ExportExcel(object sender, EventArgs e)

       FileInfo tmpl = new FileInfo(MapPath("../template/xxx.xlsx"));
       using (ExcelPackage pck = new ExcelPackage(tmpl, false))
           ExcelWorksheet ws = pck.Workbook.Worksheets["Ark1"];

           int linecnt = 5;
           foreach (DataRow dr in dsDocByAdmin.Rows)
               ws.Cells[linecnt,1].Value = dr["DocIdTxt"];
               ws.Cells[linecnt, 2].Value = dr["ImplStatTxt"];
               ws.Cells[linecnt, 3].Value = dr["ImplRemarks"];
               if (dr["DocWithDrawn"].ToString() == "True")
                    ws.Cells[linecnt, 4].Value = "Yes";
                   ws.Cells[linecnt, 4].Value = "No";


           using (ExcelRange rng = ws.Cells["C5:C"+linecnt.ToString()])
               rng.Style.WrapText = true;

           ws.Cells["B2"].Value = Request.QueryString["ITULong"];
           ws.Cells["D2"].Value = DateTime.Now;

           //Write it back to the client
           Response.AddHeader("content-disposition", "attachment; filename=xxxx" + Request.QueryString["ITUShort"].Trim() + ".xlsx");
           Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Jul 14, 2011 at 9:19 PM
Edited Jul 14, 2011 at 9:21 PM

Try putting this for the "write back to client":


pck.Stream.Seek(0, SeekOrigin.Begin);

byte[] output = new byte[pck.Stream.Length];

int bytesRead = pck.Stream.Read(output, 0, output.Length);

Response.AddHeader("content-disposition", "attachment; filename=xxxx" + Request.QueryString["ITUShort"].Trim() + ".xlsx");
Response.AddHeader("Content-Length", output.Length.ToString();
Response.ContentType = "application/octet-stream";
Jul 27, 2011 at 11:04 PM

Hi there

Thanks for your suggestion, but i still have the same problem.

When i save the file first and inspect it , it seems like it downloads the entire webpage inside, and when i open in excel say yes to fix and then save only the excel part is left. Also the size changes from above 400 kb to below 25 kb - which should be the correct size.

May have to abandon this component ...


Any suggestions is appreciated !




Jul 28, 2011 at 4:38 PM

Is this the same problem I'm having?  Is your error message similar to "Repaired Part: /xl/worksheets/sheet3.xml part with XML error.  Load error. Line 1, column 235."  If so it is because the Dimension tag in the XML for the worksheet isn't getting saved correctly, it's missing the column information. See  I keep meaning to look at the code to see if I can fix it myself, but just don't have the time right now and there's more pressing problems with epplus that have a bigger impact (Formulas getting corrupted on row/column inserts for one) that I'll look at first... when I get the time.  

Aug 1, 2011 at 10:43 PM

I am having the same problem.  The byte array that is coming back in the stream is really large.  over 45k for a file that should have only 2-300 bytes of data.  You suppose that the unreadable text is the extra stuff?

Aug 2, 2011 at 4:27 PM
Edited Aug 2, 2011 at 4:28 PM

Maybe it is another problem, like bad formula format, bad merging, etc. Open your .xlsx file with notepad, if you didnt see html code from your page, it isnt html trash. So, you need to check other things.


From FAQ...

I get an error that Excel has found unreadable content when I open my generated document?
Check your Formulas and Numberformats. Formulas and numberformats are not validated by the library so if you enter anything wrong the package will be corrupt. Use the English formula names. Formula parameters are separated by commas (,), string parameters use double quotes (").


Use culture independent number formats: dot (.) for decimal, comma (thousand). 
The easiest way to check a format or a formula is to create an Excel file --> Do the formatting / Add the formulas --> Save it as XLSX ---> Rename the file *.zip. Extract the file and have a look at the number formats in the \xl\styles.xml file and formulas in \xl\worksheets\sheet#.xml.

Jul 24, 2013 at 1:29 PM
I just fixed this problem. In my case this was being caused as the ASPX page response was also being sent after the Excel file.

EPPlus ASP.NET sample shows how to so it. Refer to GetSample.aspx in samples.

ASPX page should be very minimal i.e. first line only.