gpt4 book ai didi

java - 在浏览器中下载 Excel : Not able to prompt out save button

转载 作者:行者123 更新时间:2023-12-01 13:52:39 34 4
gpt4 key购买 nike

我预计它会有一个提示屏幕,要求用户打开、保存或取消。

从我的代码下面,我尝试使用 FileOutputStream 将文件保存到特定位置,但是我该如何做像下面的屏幕截图这样的事情?

预期截图: enter image description here

下面是我的代码:

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();
}

最佳答案

我找到了自己问题的解决方案,即不允许 Ajax 下载文件。

Refer from buddy: Why threre is no way to download file using ajax request?

原因是我在 extjs 文件中调用了 ajax。海兹...

关于java - 在浏览器中下载 Excel : Not able to prompt out save button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19854573/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com