Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. package com.simbirsoft.plugins.reports;
  2.  
  3. import com.atlassian.jira.issue.Issue;
  4. import com.atlassian.jira.user.ApplicationUser;
  5. import org.apache.poi.hssf.usermodel.HSSFCellStyle;
  6. import org.apache.poi.hssf.usermodel.HSSFFont;
  7. import org.apache.poi.hssf.usermodel.HSSFSheet;
  8. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  9. import org.apache.poi.ss.usermodel.Cell;
  10. import org.apache.poi.ss.usermodel.CellType;
  11. import org.apache.poi.ss.usermodel.Row;
  12.  
  13. import java.io.File;
  14. import java.io.FileOutputStream;
  15. import java.io.IOException;
  16. import java.util.List;
  17. import java.util.Map;
  18. import java.util.Objects;
  19.  
  20. class CreationExcelFile {
  21. private static HSSFCellStyle createStyleForTitle(HSSFWorkbook workbook) {
  22. HSSFFont font = workbook.createFont();
  23. font.setBold(true);
  24. HSSFCellStyle style = workbook.createCellStyle();
  25. style.setFont(font);
  26. return style;
  27. }
  28.  
  29. static void createExcelReport(Map<ApplicationUser, List<Issue>> map, String projectName) throws IOException {
  30. HSSFWorkbook workbook = new HSSFWorkbook();
  31. HSSFSheet sheet = workbook.createSheet("DymanicReport");
  32.  
  33. int rownum = 0;
  34. Cell cell;
  35. Row row;
  36. HSSFCellStyle style = createStyleForTitle(workbook);
  37.  
  38. row = sheet.createRow(rownum);
  39.  
  40. cell = row.createCell(0, CellType.STRING);
  41. cell.setCellValue("Название задачи");
  42. cell.setCellStyle(style);
  43.  
  44. cell = row.createCell(1, CellType.STRING);
  45. cell.setCellValue("Тип задачи");
  46. cell.setCellStyle(style);
  47.  
  48. cell = row.createCell(2, CellType.STRING);
  49. cell.setCellValue("Статус");
  50. cell.setCellStyle(style);
  51.  
  52. cell = row.createCell(3, CellType.STRING);
  53. cell.setCellValue("Название проекта");
  54. cell.setCellStyle(style);
  55.  
  56. cell = row.createCell(4, CellType.STRING);
  57. cell.setCellValue("Hours (all)");
  58. cell.setCellStyle(style);
  59.  
  60. cell = row.createCell(5, CellType.STRING);
  61. cell.setCellValue("Description");
  62. cell.setCellStyle(style);
  63.  
  64. cell = row.createCell(6, CellType.STRING);
  65. cell.setCellValue("Планируемое время (часы)");
  66. cell.setCellStyle(style);
  67.  
  68. cell = row.createCell(7, CellType.STRING);
  69. cell.setCellValue("Date");
  70. cell.setCellStyle(style);
  71.  
  72. cell = row.createCell(8, CellType.STRING);
  73. cell.setCellValue("Hours (all, billable)");
  74. cell.setCellStyle(style);
  75.  
  76. cell = row.createCell(9, CellType.STRING);
  77. cell.setCellValue("Код задачи");
  78. cell.setCellStyle(style);
  79.  
  80. // Data
  81. for (ApplicationUser user : map.keySet()) {
  82.  
  83. List<Issue> issues = map.get(user);
  84. rownum++;
  85. cell = row.createCell(0, CellType.STRING);
  86. cell.setCellValue(user.getDisplayName());
  87.  
  88. for (Issue issue : issues) {
  89. rownum++;
  90. row = sheet.createRow(rownum);
  91. // Название задачи
  92. cell = row.createCell(0, CellType.STRING);
  93. cell.setCellValue(issue.getSummary());
  94. // Тип задачи
  95. cell = row.createCell(1, CellType.STRING);
  96. cell.setCellValue(Objects.requireNonNull(issue.getIssueType()).getName());
  97. // Статус
  98. cell = row.createCell(2, CellType.STRING);
  99. cell.setCellValue(issue.getStatus().getSimpleStatus().getName());
  100. // Название проекта
  101. cell = row.createCell(3, CellType.STRING);
  102. cell.setCellValue(projectName);
  103. // Hours (all)
  104. cell = row.createCell(4, CellType.STRING);
  105. cell.setCellValue(issue.getTimeSpent());
  106. // Description
  107. cell = row.createCell(5, CellType.STRING);
  108. cell.setCellValue(issue.getDescription());
  109. // Планируемое время (часы)
  110. cell = row.createCell(6, CellType.STRING);
  111. cell.setCellValue(issue.getEstimate());
  112. // Date
  113. cell = row.createCell(7, CellType.STRING);
  114. cell.setCellValue(issue.getCreated());
  115. // Hours (all, billable)
  116. cell = row.createCell(8, CellType.STRING);
  117. cell.setCellValue("??");
  118. // Код задачи
  119. cell = row.createCell(9, CellType.STRING);
  120. cell.setCellValue(issue.getKey());
  121. }
  122. }
  123.  
  124. File file = new File("/home/artur/jira-reports/report.xls");
  125. file.getParentFile().mkdirs();
  126. /Users/arturisart/IdeaProjects/jira-plugins/jira-report-plugin/src/main/java/com/simbirsoft/plugins/converter/CreationExcelFile.java
  127.  
  128. FileOutputStream outFile = new FileOutputStream(file);
  129. workbook.write(outFile);
  130. System.out.println("Created file: " + file.getAbsolutePath());
  131. }
  132.  
  133. Bonus (E)
  134. String formula = "0.1*C" + (rownum + 1) + "*D" + (rownum + 1);
  135. cell = row.createCell(4, CellType.FORMULA);
  136. cell.setCellFormula(formula);
  137.  
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement