MVC| .Net| Excel export not responding when opened in MS Excel


April 2019


119 time


Genterate an excel file from a view, is working fine if file has less data content but when the size gets bigger the file is not responding in MS-Exce. when i tried to open it, a message gets poped up showing:

file is croupted or unsafe

and if I click yes to open, it fails to respond after taking to much time to load.

The code used to generate excel:

                Response.ContentType = "application/ms-excel";
                Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + ".xls\"");
                Response.Write("<html xmlns:x='urn:schemas-microsoft-com:office:excel'>");
                return View(data);

Further, I also tried different options of ContentType and Extension but not get the result:

ContentType                         Extension       Result
application/ms-excel                .xls             No(Same issue)
application/            .xls             No(Same issue)
application/ms-excel                .xlsx            No(Same issue)
application/            .xlsx            No(Same issue)
officedocument.spreadsheetml.sheet  .xlsx            file opened a blank sheet

0 answers