Home > Misc > Excel completed file level validation and repair – message while opening excel file

Excel completed file level validation and repair – message while opening excel file

Hi,

In one of my XRM implementation i used OpenXML.sdk to read/write excel files.

I was getting below screen while opening the created excel file from .aspx page.

Repairing file

Repairing file

Here is the code Iused to pop the excel file from .aspx page

Response.ClearHeaders();

Response.ClearContent();

Response.ContentType = “application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml”;

Response.AddHeader(“Content-Disposition”, “sample.xlsx”);

Response.BinaryWrite(outputFileBytes);

Response.Flush();

Response.End();

Fix  :-

  • There might be many reasons for this warning message
  • In my case, I mistakenly added <script> tag to my ‘Response’ object
  • So when you open the file, Excel application repairs the content by removing the <script> tag
  • This is the reason you get the message window
  • To verify whether the excel file corrupted
    • Save the Excel file locally
    • Open the Excel file with notepad
    • Check if any <script> tag exists

Open Excel using notepad

Hope it helps 🙂

Advertisement
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: