poi导出excel

川长思鸟来 2022-05-29 01:28 392阅读 0赞
  1. @RequestMapping("/export/score")
  2. public void exportClassScore(HttpServletRequest request, HttpServletResponse response) throws IOException {
  3. ServletOutputStream out = response.getOutputStream();
  4. String fileName = "导入模版.xls";
  5. response.setHeader("Content-Disposition", "attachment;filename="+ new String(fileName.getBytes(),"ISO-8859-1"));
  6. examPaperService.exportClassScore(out);
  7. }
  8. @Override
  9. public void exportClassScore(ServletOutputStream out) {
  10. HSSFWorkbook book = new HSSFWorkbook();
  11. String sheetName = "导入模版";
  12. HSSFSheet sheet = book.createSheet(sheetName);
  13. HSSFRow row_1 = sheet.createRow(0);
  14. row_1.createCell(0).setCellValue("");
  15. row_1.createCell(1).setCellValue("最高气温");
  16. row_1.createCell(2).setCellValue("最低气温");
  17. row_1.createCell(3).setCellValue("平均气温");
  18. HSSFRow row_2 = sheet.createRow(1);
  19. row_2.createCell(0).setCellValue("周一");
  20. row_2.createCell(1).setCellValue("12.0");
  21. row_2.createCell(2).setCellValue("23.0");
  22. row_2.createCell(3).setCellValue("10.0");
  23. HSSFRow row_3 = sheet.createRow(2);
  24. row_3.createCell(0).setCellValue("周二");
  25. row_3.createCell(1).setCellValue("11.0");
  26. row_3.createCell(2).setCellValue("24.0");
  27. row_3.createCell(3).setCellValue("9.0");
  28. HSSFRow row_4 = sheet.createRow(3);
  29. row_4.createCell(0).setCellValue("周三");
  30. row_4.createCell(1).setCellValue("12.5");
  31. row_4.createCell(2).setCellValue("22.0");
  32. row_4.createCell(3).setCellValue("11.0");
  33. HSSFRow row_5 = sheet.createRow(4);
  34. row_5.createCell(0).setCellValue("周四");
  35. row_5.createCell(1).setCellValue("13.5");
  36. row_5.createCell(2).setCellValue("20.0");
  37. row_5.createCell(3).setCellValue("12.0");
  38. HSSFRow row_6 = sheet.createRow(5);
  39. row_6.createCell(0).setCellValue("周五");
  40. row_6.createCell(1).setCellValue("16.0");
  41. row_6.createCell(2).setCellValue("24.0");
  42. row_6.createCell(3).setCellValue("12.0");
  43. try {
  44. book.write(out);
  45. book.close();
  46. } catch (IOException e) {
  47. e.printStackTrace();
  48. }
  49. }

发表评论

表情:
评论列表 (有 0 条评论,392人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Java POI导出Excel

    最近在项目中,需要做一个Excel导出功能,当时由于时间比较紧,忙于交互,因此草草的把功能实现就完了,做的比较Lower,我们都知道,Excel导出,一般都会有表头和内容两部分