PageRenderTime 51ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/Excel/ExcelBetreuerinnen.java

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