I expected it will have a prompt-out screen to asking user to Open or Save or Cancel.
From below my code, i try FileOutputStream is work to save the file into a specific location, but how can i do something like below my screenshot?
Expected screenshot:
Below is my code:
try {
/* Create Workbook and Worksheet XLSX Format */
XSSFWorkbook my_workbook = new XSSFWorkbook();
XSSFSheet my_sheet = my_workbook.createSheet("Cell Font");
/* Get access to XSSFCellStyle */
XSSFCellStyle my_style = my_workbook.createCellStyle();
/* We will now specify a background cell color */
my_style.setFillPattern(XSSFCellStyle.FINE_DOTS);
my_style.setFillForegroundColor(IndexedColors.BLUE.getIndex());
my_style.setFillBackgroundColor(IndexedColors.RED.getIndex());
/* Create a row in the sheet */
Row row = my_sheet.createRow(0);
/* Create a cell */
Cell cell = row.createCell(0);
cell.setCellValue("Cell Fill Color Test");
/* Attach the style to the cell */
cell.setCellStyle(my_style);
/* Write changes to the workbook */
// OutputStream out = new FileOutputStream(
// new File(ExcelConstant.TEST));
// my_workbook.write(out);
// out.close();
OutputStream output = response.getOutputStream();
// response.setContentType("application/x-download");
// response.setHeader("Content-Disposition", "attachment; filename=MyExcel.xls");
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment; filename=Excel.xlsx");
my_workbook.write(output);
output.close();
}