Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.simbirsoft.plugins.reports;
- import com.atlassian.jira.issue.Issue;
- import com.atlassian.jira.user.ApplicationUser;
- import org.apache.poi.hssf.usermodel.HSSFCellStyle;
- import org.apache.poi.hssf.usermodel.HSSFFont;
- import org.apache.poi.hssf.usermodel.HSSFSheet;
- import org.apache.poi.hssf.usermodel.HSSFWorkbook;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.ss.usermodel.CellType;
- import org.apache.poi.ss.usermodel.Row;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.util.List;
- import java.util.Map;
- import java.util.Objects;
- class CreationExcelFile {
- private static HSSFCellStyle createStyleForTitle(HSSFWorkbook workbook) {
- HSSFFont font = workbook.createFont();
- font.setBold(true);
- HSSFCellStyle style = workbook.createCellStyle();
- style.setFont(font);
- return style;
- }
- static void createExcelReport(Map<ApplicationUser, List<Issue>> map, String projectName) throws IOException {
- HSSFWorkbook workbook = new HSSFWorkbook();
- HSSFSheet sheet = workbook.createSheet("DymanicReport");
- int rownum = 0;
- Cell cell;
- Row row;
- HSSFCellStyle style = createStyleForTitle(workbook);
- row = sheet.createRow(rownum);
- cell = row.createCell(0, CellType.STRING);
- cell.setCellValue("Название задачи");
- cell.setCellStyle(style);
- cell = row.createCell(1, CellType.STRING);
- cell.setCellValue("Тип задачи");
- cell.setCellStyle(style);
- cell = row.createCell(2, CellType.STRING);
- cell.setCellValue("Статус");
- cell.setCellStyle(style);
- cell = row.createCell(3, CellType.STRING);
- cell.setCellValue("Название проекта");
- cell.setCellStyle(style);
- cell = row.createCell(4, CellType.STRING);
- cell.setCellValue("Hours (all)");
- cell.setCellStyle(style);
- cell = row.createCell(5, CellType.STRING);
- cell.setCellValue("Description");
- cell.setCellStyle(style);
- cell = row.createCell(6, CellType.STRING);
- cell.setCellValue("Планируемое время (часы)");
- cell.setCellStyle(style);
- cell = row.createCell(7, CellType.STRING);
- cell.setCellValue("Date");
- cell.setCellStyle(style);
- cell = row.createCell(8, CellType.STRING);
- cell.setCellValue("Hours (all, billable)");
- cell.setCellStyle(style);
- cell = row.createCell(9, CellType.STRING);
- cell.setCellValue("Код задачи");
- cell.setCellStyle(style);
- // Data
- for (ApplicationUser user : map.keySet()) {
- List<Issue> issues = map.get(user);
- rownum++;
- cell = row.createCell(0, CellType.STRING);
- cell.setCellValue(user.getDisplayName());
- for (Issue issue : issues) {
- rownum++;
- row = sheet.createRow(rownum);
- // Название задачи
- cell = row.createCell(0, CellType.STRING);
- cell.setCellValue(issue.getSummary());
- // Тип задачи
- cell = row.createCell(1, CellType.STRING);
- cell.setCellValue(Objects.requireNonNull(issue.getIssueType()).getName());
- // Статус
- cell = row.createCell(2, CellType.STRING);
- cell.setCellValue(issue.getStatus().getSimpleStatus().getName());
- // Название проекта
- cell = row.createCell(3, CellType.STRING);
- cell.setCellValue(projectName);
- // Hours (all)
- cell = row.createCell(4, CellType.STRING);
- cell.setCellValue(issue.getTimeSpent());
- // Description
- cell = row.createCell(5, CellType.STRING);
- cell.setCellValue(issue.getDescription());
- // Планируемое время (часы)
- cell = row.createCell(6, CellType.STRING);
- cell.setCellValue(issue.getEstimate());
- // Date
- cell = row.createCell(7, CellType.STRING);
- cell.setCellValue(issue.getCreated());
- // Hours (all, billable)
- cell = row.createCell(8, CellType.STRING);
- cell.setCellValue("??");
- // Код задачи
- cell = row.createCell(9, CellType.STRING);
- cell.setCellValue(issue.getKey());
- }
- }
- File file = new File("/home/artur/jira-reports/report.xls");
- file.getParentFile().mkdirs();
- /Users/arturisart/IdeaProjects/jira-plugins/jira-report-plugin/src/main/java/com/simbirsoft/plugins/converter/CreationExcelFile.java
- FileOutputStream outFile = new FileOutputStream(file);
- workbook.write(outFile);
- System.out.println("Created file: " + file.getAbsolutePath());
- }
- Bonus (E)
- String formula = "0.1*C" + (rownum + 1) + "*D" + (rownum + 1);
- cell = row.createCell(4, CellType.FORMULA);
- cell.setCellFormula(formula);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement