Если я записываю его на диск, файл создается правильно, но если я попытаюсь напишите ответ, я всегда получаю файл больше, чем созданный на диске, и он выглядит поврежденным.
Это мой код
Код: Выделить всё
public void getFile(@RequestBodyRequest request,HttpServletResponse response) {
String headerKey = "Content-Disposition";
response.reset();
response.resetBuffer();
String fileName = "test.xlsx";
String headerValue = String.format("attachment; filename=%s", fileName);
response.setHeader(headerKey, headerValue);
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
Workbook workbook = dcservice.getRequest(request);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
workbook.write(baos);
byte[] content = baos.toByteArray();
response.setContentLength(content.length);
try (ServletOutputStream out = response.getOutputStream()) {
out.write(content);
out.flush();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (workbook != null) {
try {
workbook.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
Может ли кто-нибудь мне помочь?
Подробнее здесь: https://stackoverflow.com/questions/791 ... apache-poi
Мобильная версия