/Users/johnr/Desktop/IA_14_-_Stage_P_Upload_all_2021-04-08/IBCompSciInternalAssessment Lara April 6th/src/ibcompsciinternalassessment/ExportData.java |
1
2
3
4
5
6 package ibcompsciinternalassessment;
7
8
9
10 @author
11
12 import java.io.FileOutputStream;
13 import java.io.IOException;
14 import java.util.ArrayList;
15 import java.util.logging.Level;
16 import java.util.logging.Logger;
17 import org.apache.poi.ss.usermodel.Cell;
18 import org.apache.poi.ss.usermodel.Row;
19 import org.apache.poi.xssf.usermodel.XSSFSheet;
20 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
21
22 public class ExportData {
23
24
25 private static int counter = 1;
26 static final String fileName = "ContributionForms";
27 static final String fileType = ".xlsx";
28
29
30 public void exportToExcel(ArrayList<Contribution> contributions) throws IOException{
31
32 XSSFWorkbook workbook = new XSSFWorkbook();
33
34 XSSFSheet sheet = workbook.createSheet("Report");
35
36 createHeader(sheet, workbook);
37
38 int rowCount = 0;
39 for (Contribution contrib : contributions) {
40
41 Row row = sheet.createRow(++rowCount);
42
43
44 Cell nameCell = row.createCell(0);
45 nameCell.setCellValue(contrib.getDonorName());
46
47
48 Cell amountCell = row.createCell(1);
49 amountCell.setCellValue(contrib.getAmountEstimated());
50
51
52 Cell dDCell = row.createCell(2);
53 dDCell.setCellValue(contrib.getDueDiligence());
54
55
56 Cell dDCommentsCell = row.createCell(3);
57 dDCell.setCellValue(contrib.getdDComments());
58
59
60 Cell bYCell = row.createCell(4);
61 bYCell.setCellValue(contrib.getBudgetYear());
62
63
64 Cell bYCommentsCell = row.createCell(5);
65 bYCommentsCell.setCellValue(contrib.getbYComments());
66
67
68 Cell retroAcceptedCell = row.createCell(6);
69 retroAcceptedCell.setCellValue(contrib.isIsRetroactivityAccepted());
70
71
72 Cell retroCommentsCell = row.createCell(7);
73 retroCommentsCell.setCellValue(contrib.getRetroComments());
74
75
76 Cell geoInterestCell = row.createCell(8);
77 geoInterestCell.setCellValue(contrib.getGeoInterestName());
78
79
80 Cell geoCommentsCell = row.createCell(9);
81 geoCommentsCell.setCellValue(contrib.getGeoComments());
82
83
84 Cell thematicCell = row.createCell(10);
85 thematicCell.setCellValue(contrib.getThematicInterest());
86
87
88 Cell repReqCell = row.createCell(11);
89 repReqCell.setCellValue(contrib.getReportingRequirements());
90
91
92 Cell visReqCell = row.createCell(12);
93 visReqCell.setCellValue(contrib.getVisibilityRequirements());
94
95
96 Cell otherCommentsCell = row.createCell(13);
97 otherCommentsCell.setCellValue(contrib.getOtherComments());
98
99
100 }
101 try (FileOutputStream outputStream = new FileOutputStream(fileName + counter+ fileType)) {
102 workbook.write(outputStream);
103 counter++;
104 } catch (IOException ex) {
105 Logger.getLogger(ExportData.class.getName()).log(Level.SEVERE, null, ex);
106 }
107
108 finally {
109
110 workbook.close();
111 }
112 }
113
114 private static void createHeader(XSSFSheet sheet, XSSFWorkbook workbook) {
115 Row headerRow = sheet.createRow(0);
116 headerRow.createCell(0).setCellValue("Donor Name");
117 headerRow.createCell(1).setCellValue("Amount Estimated");
118 headerRow.createCell(2).setCellValue("Due Diligence");
119 headerRow.createCell(3).setCellValue("DD Comments");
120 headerRow.createCell(4).setCellValue("Budget Year");
121 headerRow.createCell(5).setCellValue("Budget Comments");
122 headerRow.createCell(6).setCellValue("Retroactivity Accepted");
123 headerRow.createCell(7).setCellValue("Retroactivity Comments");
124 headerRow.createCell(8).setCellValue("Geographical Interest");
125 headerRow.createCell(9).setCellValue("Geographical Comments");
126 headerRow.createCell(10).setCellValue("Thematic Interest");
127 headerRow.createCell(11).setCellValue("Reporting Requirements");
128 headerRow.createCell(12).setCellValue("Visibility Requirements");
129 headerRow.createCell(13).setCellValue("Other Comments");
130 }
131
132 }
133