PageRenderTime 141ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/Excel/ExcelBetreuerinnenAN.java

https://bitbucket.org/tomas12/laguna
Java | 240 lines | 196 code | 33 blank | 11 comment | 32 complexity | a23302d05b5900b78bf8dd953ddf0745 MD5 | raw file
  1. package Excel;
  2. import java.io.File;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.Iterator;
  7. import java.util.LinkedHashMap;
  8. import javafx.collections.ObservableList;
  9. import org.apache.poi.hssf.util.CellRangeAddress;
  10. import org.apache.poi.hssf.util.HSSFColor.LAVENDER;
  11. import org.apache.poi.ss.usermodel.HorizontalAlignment;
  12. import org.apache.poi.xssf.usermodel.XSSFCell;
  13. import org.apache.poi.xssf.usermodel.XSSFCellStyle;
  14. import org.apache.poi.xssf.usermodel.XSSFFont;
  15. import org.apache.poi.xssf.usermodel.XSSFRichTextString;
  16. import org.apache.poi.xssf.usermodel.XSSFRow;
  17. import org.apache.poi.xssf.usermodel.XSSFSheet;
  18. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  19. import Objekte.Betreuerin;
  20. import Objekte.Zahlungen;
  21. import Sort.SortDatumBetreuerin;
  22. import datenbank.Datenbank;
  23. public class ExcelBetreuerinnenAN {
  24. FileOutputStream fileOutputStream = null;
  25. public void erstelleExcel(ArrayList<String> spalten, String suchevon, String suchebis) {
  26. try {
  27. fileOutputStream = new FileOutputStream("Betreuerinnen Angefangen.xlsx");
  28. spalten.remove("Angefangen");
  29. spalten.remove("Nr");
  30. spalten.remove("Nachname");
  31. // Create Sheet.
  32. XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
  33. XSSFSheet sheet = xssfWorkbook.createSheet("Betreuerinnen");
  34. // Font setting for sheet.
  35. XSSFFont font = xssfWorkbook.createFont();
  36. font.setBoldweight((short) 700);
  37. // Create Styles for sheet.
  38. XSSFCellStyle headerStyle = xssfWorkbook.createCellStyle();
  39. headerStyle.setFillForegroundColor(LAVENDER.index);
  40. headerStyle.setFont(font);
  41. headerStyle.setAlignment(HorizontalAlignment.CENTER);
  42. XSSFCellStyle dataStyle = xssfWorkbook.createCellStyle();
  43. dataStyle.setWrapText(true);
  44. dataStyle.setAlignment(HorizontalAlignment.CENTER);
  45. Datenbank<Betreuerin> db = new Datenbank<Betreuerin>();
  46. ObservableList<Betreuerin> betreuerinnen = db
  47. .filltable(new Betreuerin());
  48. XSSFRow row = sheet.createRow(0);
  49. sheet.addMergedRegion(new CellRangeAddress(0, // first
  50. // row
  51. // (0-based)
  52. 0, // last row (0-based)
  53. 0, // first column (0-based)
  54. spalten.size() +1 // last column (0-based)
  55. ));
  56. XSSFCell headerCell0 = row.createCell(0);
  57. headerCell0.setCellStyle(headerStyle);
  58. headerCell0.setCellValue("Betreuerinnen ZENTRALTABELLE");
  59. XSSFRow headerRow = sheet.createRow(1);
  60. int count = 2;
  61. for (String spaltenname : spalten) {
  62. if (!spaltenname.equals("Angefangen")) {
  63. XSSFCell headerCell1 = headerRow.createCell(count);
  64. headerCell1.setCellStyle(headerStyle);
  65. headerCell1.setCellValue(spaltenname);
  66. count++;
  67. }
  68. }
  69. XSSFCell headerCell00 = headerRow.createCell(0);
  70. headerCell00.setCellStyle(headerStyle);
  71. headerCell00.setCellValue("Angefangen");
  72. XSSFCell headerCell1 = headerRow.createCell(1);
  73. headerCell1.setCellStyle(headerStyle);
  74. headerCell1.setCellValue("Betreuerinnen");
  75. SortDatumBetreuerin sort = new SortDatumBetreuerin();
  76. ArrayList<Betreuerin> sortierte_liste = sort
  77. .sortBetreuerin("Angefangen", betreuerinnen, suchevon, suchebis);
  78. for (int i = 0; i < sortierte_liste.size(); i++) {
  79. Betreuerin b = sortierte_liste.get(i);
  80. // Neue Zeile
  81. XSSFRow dataRow = sheet.createRow(i + 2);
  82. XSSFCell cell1 = dataRow.createCell(0);
  83. cell1.setCellStyle(dataStyle);
  84. cell1.setCellValue(new XSSFRichTextString(b.getAngefangen()));
  85. XSSFCell cell0 = dataRow.createCell(1);
  86. cell0.setCellStyle(dataStyle);
  87. cell0.setCellValue(new XSSFRichTextString(b.getNummer()+" "+b.getNachname()));
  88. for (int j = 0; j < spalten.size(); j++) {
  89. // Write data in data row
  90. XSSFCell cell = dataRow.createCell(j + 2);
  91. cell.setCellStyle(dataStyle);
  92. if (spalten.get(j).equals("Vorname")) {
  93. cell.setCellValue(new XSSFRichTextString(b
  94. .getVorname()));
  95. }
  96. if (spalten.get(j).equals("Geburtsdatum")) {
  97. cell.setCellValue(new XSSFRichTextString(b
  98. .getGeburtsdatum()));
  99. }
  100. if (spalten.get(j).equals("Geburtsname")) {
  101. cell.setCellValue(new XSSFRichTextString(b
  102. .getGeburtsname()));
  103. }
  104. if (spalten.get(j).equals("Adresse")) {
  105. cell.setCellValue(new XSSFRichTextString(b
  106. .getAdresse()));
  107. }
  108. if (spalten.get(j).equals("Stadt")) {
  109. cell.setCellValue(new XSSFRichTextString(b.getStadt()));
  110. }
  111. if (spalten.get(j).equals("PLZ")) {
  112. cell.setCellValue(new XSSFRichTextString(b.getPlz()));
  113. }
  114. if (spalten.get(j).equals("Email")) {
  115. cell.setCellValue(new XSSFRichTextString(b.getEmail()));
  116. }
  117. if (spalten.get(j).equals("SK Handy")) {
  118. cell.setCellValue(new XSSFRichTextString(b
  119. .getSkHandy()));
  120. }
  121. if (spalten.get(j).equals("AT Handy")) {
  122. cell.setCellValue(new XSSFRichTextString(b
  123. .getAtHandy()));
  124. }
  125. if (spalten.get(j).equals("SK Festnetz")) {
  126. cell.setCellValue(new XSSFRichTextString(b
  127. .getSkFestnetz()));
  128. }
  129. if (spalten.get(j).equals("Personalausweis")) {
  130. cell.setCellValue(new XSSFRichTextString(b
  131. .getPersonalausweis()));
  132. }
  133. if (spalten.get(j).equals("Reisepass")) {
  134. cell.setCellValue(new XSSFRichTextString(b
  135. .getReisepass()));
  136. }
  137. if (spalten.get(j).equals("Personalstand")) {
  138. cell.setCellValue(new XSSFRichTextString(b
  139. .getPersonalstand()));
  140. }
  141. if (spalten.get(j).equals("Nationalität")) {
  142. cell.setCellValue(new XSSFRichTextString(b
  143. .getNationalitat()));
  144. }
  145. if (spalten.get(j).equals("Registernummer")) {
  146. cell.setCellValue(new XSSFRichTextString(b
  147. .getRegisternummer()));
  148. }
  149. if (spalten.get(j).equals("Steuernummer")) {
  150. cell.setCellValue(new XSSFRichTextString(b
  151. .getSteuernummer()));
  152. }
  153. if (spalten.get(j).equals("VSNR")) {
  154. cell.setCellValue(new XSSFRichTextString(b.getVsnr()));
  155. }
  156. if (spalten.get(j).equals("MGNR")) {
  157. cell.setCellValue(new XSSFRichTextString(b.getMgnr()));
  158. }
  159. if (spalten.get(j).equals("Mutter Nachname")) {
  160. cell.setCellValue(new XSSFRichTextString(b
  161. .getMutter_nachname()));
  162. }
  163. if (spalten.get(j).equals("Mutter Vorname")) {
  164. cell.setCellValue(new XSSFRichTextString(b
  165. .getMutter_vorname()));
  166. }
  167. if (spalten.get(j).equals("Vater Nachname")) {
  168. cell.setCellValue(new XSSFRichTextString(b
  169. .getVater_nachname()));
  170. }
  171. if (spalten.get(j).equals("Vater Vorname")) {
  172. cell.setCellValue(new XSSFRichTextString(b
  173. .getVater_vorname()));
  174. }
  175. if (spalten.get(j).equals("Kontakt")) {
  176. cell.setCellValue(new XSSFRichTextString(b
  177. .getKontakt()));
  178. }
  179. if (spalten.get(j).equals("Info")) {
  180. cell.setCellValue(new XSSFRichTextString(b.getArea()));
  181. }
  182. if (spalten.get(j).equals("Aufgehört")) {
  183. cell.setCellValue(new XSSFRichTextString(b.getAufgehort()));
  184. }
  185. }
  186. }
  187. for (int i = 0; i <= spalten.size() + 1; i++) {
  188. sheet.autoSizeColumn(i);
  189. }
  190. // write in excel
  191. xssfWorkbook.write(fileOutputStream);
  192. } catch (Exception e) {
  193. e.printStackTrace();
  194. } finally {
  195. /*
  196. * Close File Output Stream
  197. */
  198. try {
  199. if (fileOutputStream != null) {
  200. fileOutputStream.close();
  201. }
  202. } catch (IOException ex) {
  203. ex.printStackTrace();
  204. }
  205. }
  206. }
  207. }