I'm new to GWT and in my company i was asked to make some changes in one of our applications. Currently the Program generates reports in .xls format. Now we want to change it to .xlsx
public class Download extends HttpServlet {
private static final long serialVersionUID = 5580666921970339383L;
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String filename = (String)request.getSession().getAttribute(CrossReportConstants.ATTR_FILENAME);
byte[] data = (byte[])request.getSession().getAttribute(CrossReportConstants.ATTR_REPORT);
request.getSession().setAttribute(CrossReportConstants.ATTR_FILENAME, null);
request.getSession().setAttribute(CrossReportConstants.ATTR_REPORT, null);
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=" + filename);
response.setHeader("Pragma", "no-cache");
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.setContentLength(data.length);
try {
InputStream in = new ByteArrayInputStream(data);
ServletOutputStream out = response.getOutputStream();
byte[] outputByte = new byte[4096];
// copy binary contect to output stream
while (in.read(outputByte, 0, 4096) != -1) {
out.write(outputByte, 0, 4096);
}
in.close();
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
I changed response.setContentType("application/vnd.ms-excel");
to
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
and I changed the filename to exampleReport.xlsx When i test the Application i can download the report but i cannot open it - Excel tells me the file is corrupted. (the file has the right size and when i open it in a text editor i can see the content) Did I miss something? Thanks in advance