My java application has problems downloading XLSX files.
following the example shown in this link: Create an Excel file to load using the Apache POI , I tried two configurations for loading / saving the table.
First the .XLS file:
response.setContentType("application/ms-excel"); response.setHeader("Content-Disposition", "attachment; filename=testxls.xls"); HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(); HSSFRow row = sheet.createRow(0); HSSFCell cell = row.createCell(0); cell.setCellValue("Some text"); ByteArrayOutputStream outByteStream = new ByteArrayOutputStream(); wb.write(outByteStream); byte[] outArray = outByteStream.toByteArray(); OutputStream outStream = response.getOutputStream(); outStream.write(outArray); outStream.flush();
It works.
Then I tried with the XLSX file:
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setHeader("Content-Disposition", "attachment; filename=testxls.xlsx"); XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet(); XSSFRow row = sheet.createRow(0); XSSFCell cell = row.createCell(0); cell.setCellValue("Some text"); ByteArrayOutputStream outByteStream = new ByteArrayOutputStream(); wb.write(outByteStream); byte[] outArray = outByteStream.toByteArray(); OutputStream outStream = response.getOutputStream(); outStream.write(outArray); outStream.flush();
When I try to do this, I get a message: " Excel found unreadable content in" testxls.xlsx. "Do you want to restore the contents of this book? .... "
Despite this message, the spreadsheet opens normally, but I really want to delete this message.
Any ideas?
source share