/src/test/java/com/eastrobot/doc/demo/Tests.java

https://github.com/ekoz/kbase-doc · Java · 79 lines · 61 code · 9 blank · 9 comment · 2 complexity · 6f690abcac3f762beeb455cebc72b03d MD5 · raw file

  1. /*
  2. * Powered by http://ibotstat.com
  3. */
  4. package com.eastrobot.doc.demo;
  5. import org.apache.commons.io.FileUtils;
  6. import org.apache.poi.ss.usermodel.CellType;
  7. import org.apache.poi.ss.usermodel.Row;
  8. import org.apache.poi.ss.usermodel.Sheet;
  9. import org.apache.poi.ss.usermodel.Workbook;
  10. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  11. import org.junit.Test;
  12. import java.io.File;
  13. import java.io.FileOutputStream;
  14. import java.io.IOException;
  15. import java.io.OutputStream;
  16. import java.util.Calendar;
  17. import java.util.Date;
  18. import java.util.List;
  19. /**
  20. * @author <a href="mailto:eko.z@outlook.com">eko.zhan</a>
  21. * @version v1.0
  22. * @date 2019/12/30 13:12
  23. */
  24. public class Tests {
  25. @Test
  26. public void test() throws IOException {
  27. Workbook wb = new XSSFWorkbook();
  28. Sheet sheet = wb.createSheet("会计考试");
  29. addTitle(sheet);
  30. List<String> list = FileUtils.readLines(new File("E:\\会计成绩名单.txt"), "UTF-8");
  31. int i=0;
  32. for (String line : list){
  33. if (line.contains("麻城")){
  34. line = line.substring(1, line.length()-1).replace("\"", "");
  35. System.out.println(line);
  36. String[] arr = line.split(",");
  37. i++;
  38. Row row = sheet.createRow(i);
  39. row.createCell(0).setCellValue(arr[0]);
  40. row.createCell(1).setCellValue(arr[1]);
  41. row.createCell(2).setCellValue(arr[2]);
  42. row.createCell(3).setCellValue(arr[3]);
  43. row.createCell(4).setCellValue(arr[4]);
  44. row.createCell(5).setCellValue(arr[5]);
  45. row.createCell(6).setCellValue(arr[6]);
  46. row.createCell(7).setCellValue(arr[7]);
  47. row.createCell(8).setCellValue(arr[8]);
  48. row.createCell(9).setCellValue(arr[9]);
  49. }
  50. }
  51. System.out.println(i);
  52. //==============================================================
  53. try (OutputStream fileOut = new FileOutputStream("E://workbook.xlsx")) {
  54. wb.write(fileOut);
  55. }
  56. }
  57. private void addTitle(Sheet sheet){
  58. Row row = sheet.createRow(0);
  59. row.createCell(0).setCellValue("专业名称");
  60. row.createCell(1).setCellValue("考号");
  61. row.createCell(2).setCellValue("学生姓名");
  62. row.createCell(3).setCellValue("学校名称");
  63. row.createCell(4).setCellValue("总分");
  64. row.createCell(5).setCellValue("全省排名");
  65. row.createCell(6).setCellValue("全省最高分");
  66. row.createCell(7).setCellValue("全省平均分");
  67. row.createCell(8).setCellValue("学校平均分");
  68. row.createCell(9).setCellValue("全省参考人数");
  69. }
  70. }