Export Excel shows a warning message and then shows file corrupted

1.1k Views Asked by At

I have an application deployed on WebLogic12c-- app was recently migrated to 12c. When I try to export a report to an excel, it shows me a warning message(the file you are trying to open is in a different format than specified by the file extension....) and then says the file is corrupted. But the same file if I try to save and open, it still shows the warning message but it opens in excel with data. Here is my export excel action class...

String header = "attachment; filename=" + filename + "-"
              + new Date().getTime() + ".xls;";
response.setContentType("application/vnd.ms-excel;name=\"bestellnummer\"");
response.setHeader("Content-Disposition",header);

I am not sure if the issue is in WebLogic or code.

1

There are 1 best solutions below

2
On

Try change:

String header = "attachment; filename=" + filename + "-"
          + new Date().getTime() + ".xls;";

to

String header = "attachment; filename=" + filename + "-"
          + new Date().getTime() + ".xlsx;";

This is a default message of Excel, because you is creating a file in the new format (.xlsx) and naming with old extension (.xls).