diff --git a/README.md b/README.md index 728fb233..59749e57 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,9 @@ public class Down { @GetMapping("/a.htm") public void cooperation(HttpServletRequest request, HttpServletResponse response) { ServletOutputStream out = response.getOutputStream(); + response.setContentType("multipart/form-data"); + response.setCharacterEncoding("utf-8"); + response.setHeader("Content-disposition", "attachment;filename="+fileName+".xlsx"); ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX, true); String fileName = new String(("UserInfo " + new SimpleDateFormat("yyyy-MM-dd").format(new Date())) .getBytes(), "UTF-8"); @@ -134,9 +137,7 @@ public class Down { sheet1.setSheetName("第一个sheet"); writer.write0(getListString(), sheet1); writer.finish(); - response.setContentType("multipart/form-data"); - response.setCharacterEncoding("utf-8"); - response.setHeader("Content-disposition", "attachment;filename="+fileName+".xlsx"); + out.flush(); } }