我想下載創建的excel文件。我正在使用POI。此北京時間我的代碼:使用HttpServlet彈出下載excel
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=" + filename);
OutputStream out = response.getOutputStream();
HSSFWorkbook workbook = new HSSFWorkbook();
... // add some sheets
workbook.write(out);
這是我RestService
@Autowired
Excel excel;
@RequestMapping(path = "/excel/{testId}", method = RequestMethod.GET)
public ResponseEntity createFile(HttpServletResponse response, @PathVariable Integer testId) {
try {
excel.createFile(response, testId);
} catch (IOException e) {
e.printStackTrace();
}
return new ResponseEntity(HttpStatus.OK);
}
存儲文件的本地作品。
謝謝!
您需要提供比這更多的代碼。你如何創建工作簿?你的spring控制器或servlet的完整方法是什麼? –
嘿我編輯我的答案希望它會幫助 – 1thingtodo