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

Refresh

April 2019

Views

119 time

1

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.Clear();
                Response.ClearHeaders();
                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/vnd.ms-excel            .xls             No(Same issue)
application/ms-excel                .xlsx            No(Same issue)
application/vnd.ms-excel            .xlsx            No(Same issue)
application/vnd.openxmlformats-
officedocument.spreadsheetml.sheet  .xlsx            file opened a blank sheet

0 answers