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

"unreadable content" error when opening Excel file created via ClosedXML

May 16, 2012 at 3:19 AM

I am creating an XLSX file in VB.Net with two sheets - each created from a DataTable.

When I open the file in Excel 2010, I get the following error - any suggestions on how to resolve this issue would be greatly appreciated.

Excel found unreadable content in 'C:\temp\test.xlsx'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes.

When I click 'Yes', the workbook opens and contains all of the expected rows and columns, however, a second popup appears titled "Repairs to 'test.xlsx'" with the message "Excel was able to open the file by repairing or removing the unreadable content."  The detail area of this popup contains the following:

Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded.
Repaired Records: Table from /xl/tables/table.xml part (Table)

Below the detail area is a link to "view log file listing repairs".  The contents of that log file are as follows:

  <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
- <recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  <logFileName>error072760_01.xml</logFileName>
  <summary>Errors were detected in file 'C:\temp\S210_OrderPriceOverrides.xlsx'</summary>
- <repairedRecords summary="Following is a list of repairs:">
  <repairedRecord>Repaired Records: Table from /xl/tables/table.xml part (Table)</repairedRecord>
  </repairedRecords>
  </recoveryLog>

 

May 16, 2012 at 5:41 AM

Please create an issue and attach a file that's giving you problems. If possible also attach a sample/test project that recreates the error.

Thanks for the feedback.

Aug 1, 2012 at 8:17 PM

I was getting a very similar error when downloading Excel files from an ASP.NET site.  Turns out I also needed the Content-Length header.  Here's a code snippet:

 

MemoryStream stream = export.ExportEx(types, ids);
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml";
Response.AddHeader("content-disposition""attachment;filename=\"AnalysisExport.xlsx\"");
Response.AddHeader("Content-Length", stream.Length.ToString());
stream.WriteTo(Response.OutputStream);
stream.Close();
Oct 7, 2012 at 7:27 PM

In your case you need to use next utility http://www.recoverytoolbox.com/repair_excel.html which supports restoring excel files starting with MS Excel 97

Mar 27, 2014 at 1:46 PM
You may need to set the cells DataType. This is the only thing that worked in my case.

ex..

ApprovedCoursesSheet.Cell(Row, 1).DataType = XLCellValues.Text
ApprovedCoursesSheet.Cell(Row, 1).SetValue(Of Int32)(c.APPL_COURSE_ID)
ApprovedCoursesSheet.Cell(Row, 2).DataType = XLCellValues.Text
ApprovedCoursesSheet.Cell(Row, 2).SetValue(Of String)(c.APPL_COURSE_NAME)
Apr 29, 2014 at 4:56 PM
SolanumVexus wrote:
I was getting a very similar error when downloading Excel files from an ASP.NET site.  Turns out I also needed the Content-Length header.  Here's a code snippet:   MemoryStream stream = export.ExportEx(types, ids); Response.Clear(); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"; Response.AddHeader("content-disposition", "attachment;filename=\"AnalysisExport.xlsx\""); Response.AddHeader("Content-Length", stream.Length.ToString()); stream.WriteTo(Response.OutputStream); stream.Close();
Thank you SolanumVexus. You solved my problem with the Content-Length header.