我预计它将有一个提示屏幕来要求用户打开或保存或取消。
从我的代码下方,我尝试使用 FileOutputStream 将文件保存到特定位置,但是我怎样才能执行屏幕截图下方的操作?
预期截图:
下面是我的代码:
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();
}