0

I created an ".xlsx" file (CustomerData.xlsx) by using "Apache POI".

The problem is that the file is created on my TomCat Server and I have to download it.

I tried the following code, in order to download the file:

HttpServletResponse response = null;

response.setContentType("xlsx");
response.setHeader(
    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    "attachment; filename=C:\CustomerData.xlsx");
try {
    workbook.write(response.getOutputStream());
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

but unfortunately, it does not seem to work.

In case you have any idea or suggestion, do not hesitate posting it.

Todd
  • 30,472
  • 11
  • 81
  • 89
Origamer7
  • 315
  • 3
  • 17

1 Answers1

1

You mix content type and attachment information into a single header which cannot work.

Instead write

response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment;filename=CustomerData.xlsx");
wero
  • 32,544
  • 3
  • 59
  • 84