不是从InputStream中read,然后outputStream再write
@RequestMapping("download4Excel") public void download4Excel(HttpServletResponse response){ XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet("测试Sheet"); sheet.setColumnWidth(1, 7000); Row row = sheet.createRow(0); Cell cell = row.createCell(1); cell.setCellValue("德玛西亚"); try { response.setContentType("multipart/form-data"); response.setHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode("测试生成Excel文件.xlsx", "utf-8")); OutputStream outputStream = response.getOutputStream(); workbook.write(outputStream); outputStream.close(); workbook.close(); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }