1.前台
function btn_download() {
window.open('/Agvs/Path/Download', '_blank');
}
2.后台Controller
/**
* 路径下载
*
* @param request
* @param response
* @throws Exception
*/
@RequestMapping(value = "/Download", method = {RequestMethod.GET})
public void download(HttpServletRequest request, HttpServletResponse response) throws Exception {
try {
List<Map<String, Object>> list = pathService.getPathList();
Map<String, String> headMap = new LinkedHashMap<>();
headMap.put("PointStart", "起始点编号");
headMap.put("PointEnd", "结束点编号");
XSSFWorkbook wb = ExcelUtils.exportExcel2(list, headMap, "Path", false);
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-disposition", "attachment;filename=path.xlsx");
OutputStream ouputStream = response.getOutputStream();
wb.write(ouputStream);
ouputStream.flush();
ouputStream.close();
} catch (Exception ex) {
}
}