【发布时间】:2018-05-27 21:02:43
【问题描述】:
我的 html 页面上有这个按钮。 当我点击它时,exportCOAExcel 被触发。 然后生成一个excel工作簿并保存到一个路径中。
我想要一个提示来说明您要将文件下载到哪个路径?或保存到浏览器默认的“下载”文件夹位置。
@GetMapping(value = "/coaExport", params = "action=excel")
public void exportCOAExcel(HttpServletRequest request, HttpServletResponse response) throws IOException {
XSSFWorkbook workbook = new XSSFWorkbook();
//loogic to fill up the excel workbook with data
FileOutputStream outputStream = new
FileOutputStream("C:\\Users\\user\\Desktop\\revenue.xls");
workbook.write(outputStream);
outputStream.close();
}
【问题讨论】:
-
我假设您的 Web 应用程序正在服务器上运行 - 将文件保存到服务器上的特定位置没有意义 - 相反,您需要将文件发送到 HttpServletResponse 并设置正确的标头.您无法选择文件的保存位置 - 这取决于用户的浏览器。
-
如何将文件发送到响应?
标签: java excel spring-boot