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

/src/main/java/Excel/ExcelFamilienAU.java

https://bitbucket.org/tomas12/laguna
Java | 868 lines | 709 code | 84 blank | 75 comment | 175 complexity | 6e91f341ca470ddad3adac6f482a8d65 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.BetreuungFamilie;
  20. import Objekte.Familie;
  21. import Objekte.Zahlungen;
  22. import Sort.SortDatumFamilie;
  23. import datenbank.Datenbank;
  24. public class ExcelFamilienAU {
  25. FileOutputStream fileOutputStream = null;
  26. @SuppressWarnings("deprecation")
  27. public void erstelleExcel(ArrayList<String> spalten, int patient1,
  28. int patient2, int kontaktperson1, int kontaktperson2, String von, String bis) {
  29. try {
  30. fileOutputStream = new FileOutputStream("Familien Angefangen.xlsx");
  31. patient1 = patient1 + 1;
  32. spalten.remove("P Aufgehรถrt");
  33. if(spalten.remove(" Nr")){
  34. patient1 = patient1 - 1;
  35. }
  36. if(spalten.remove("P Nachname")){
  37. patient1 = patient1 - 1;
  38. }
  39. // Create Sheet.
  40. XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
  41. XSSFSheet sheet = xssfWorkbook.createSheet("Familien");
  42. // Font setting for sheet.
  43. XSSFFont font = xssfWorkbook.createFont();
  44. font.setBoldweight((short) 700);
  45. // Create Styles for sheet.
  46. XSSFCellStyle headerStyle = xssfWorkbook.createCellStyle();
  47. headerStyle.setFillForegroundColor(LAVENDER.index);
  48. headerStyle.setFont(font);
  49. headerStyle.setAlignment(HorizontalAlignment.CENTER);
  50. XSSFCellStyle dataStyle = xssfWorkbook.createCellStyle();
  51. dataStyle.setWrapText(true);
  52. dataStyle.setAlignment(HorizontalAlignment.CENTER);
  53. Datenbank<Familie> db = new Datenbank<Familie>();
  54. ObservableList<Familie> familien = db
  55. .filltable(new Familie());
  56. XSSFRow zeile = sheet.createRow(0);
  57. sheet.addMergedRegion(new CellRangeAddress(0, // first
  58. // row
  59. // (0-based)
  60. 0, // last row (0-based)
  61. 0, // first column (0-based)
  62. spalten.size()+1 // last column (0-based)
  63. ));
  64. XSSFCell headerCell0 = zeile.createCell(0);
  65. headerCell0.setCellStyle(headerStyle);
  66. headerCell0.setCellValue("Familien ZENTRALTABELLE");
  67. XSSFRow zweiteZeile = sheet.createRow(2);
  68. int count = 2;
  69. for (String spaltenname : spalten) {
  70. if (!spaltenname.equals("Aufgehรถrt")) {
  71. XSSFCell spaltenCells = zweiteZeile.createCell(count);
  72. spaltenCells.setCellStyle(headerStyle);
  73. spaltenCells.setCellValue(spaltenname.substring(2));
  74. count++;
  75. }
  76. }
  77. XSSFCell headerCell00 = zweiteZeile.createCell(0);
  78. headerCell00.setCellStyle(headerStyle);
  79. headerCell00.setCellValue("Aufgehรถrt");
  80. XSSFCell spaltenCells = zweiteZeile.createCell(1);
  81. spaltenCells.setCellStyle(headerStyle);
  82. spaltenCells.setCellValue("Familien");
  83. SortDatumFamilie sort = new SortDatumFamilie();
  84. ArrayList<Familie> sortierte_liste = sort
  85. .sortFamilie("Aufgehรถrt", familien, von, bis);
  86. for (int i = 0; i < sortierte_liste.size(); i++) {
  87. Familie f = sortierte_liste.get(i);
  88. // Neue Zeile
  89. XSSFRow dataRow = sheet.createRow(i + 3);
  90. XSSFCell cell1f = dataRow.createCell(0);
  91. cell1f.setCellStyle(dataStyle);
  92. cell1f.setCellValue(new XSSFRichTextString(f.getAufgehort()));
  93. XSSFCell cell0 = dataRow.createCell(1);
  94. cell0.setCellStyle(dataStyle);
  95. cell0.setCellValue(new XSSFRichTextString(f.getNummer()+" "+f.getNachname_patient()));
  96. for (int j = 0; j < spalten.size(); j++) {
  97. // Write data in data row
  98. XSSFCell cell1 = dataRow.createCell(j + 2);
  99. cell1.setCellStyle(dataStyle);
  100. if (spalten.get(j).equals("K1 Beziehung")) {
  101. cell1.setCellValue(new XSSFRichTextString(""
  102. + f.getBeziehungsstand1()));
  103. }
  104. if (spalten.get(j).equals("K2 Beziehung")) {
  105. cell1.setCellValue(new XSSFRichTextString(""
  106. + f.getBeziehungsstand2()));
  107. }
  108. if (spalten.get(j).equals(" Nr")) {
  109. cell1.setCellValue(new XSSFRichTextString(""
  110. + f.getNummer()));
  111. }
  112. if (spalten.get(j).equals("P Nachname")) {
  113. cell1.setCellValue(new XSSFRichTextString(f
  114. .getNachname_patient()));
  115. }
  116. if (spalten.get(j).equals("P Betreuerin 1")) {
  117. ArrayList<BetreuungFamilie> al = f.getBetreuung();
  118. if (al != null && al.size() >= 1) {
  119. BetreuungFamilie neu = al.get(al.size() - 1);
  120. cell1.setCellValue(new XSSFRichTextString(neu
  121. .getBetreuerin_nummer()
  122. + " "
  123. + neu.getBetreuerin_nachname()));
  124. }
  125. }
  126. if (spalten.get(j).equals("P Betreuerin 2")) {
  127. ArrayList<BetreuungFamilie> al = f.getBetreuung();
  128. if (al != null && al.size() >= 2) {
  129. BetreuungFamilie neu = al.get(al.size() - 2);
  130. cell1.setCellValue(new XSSFRichTextString(neu
  131. .getBetreuerin_nummer()
  132. + " "
  133. + neu.getBetreuerin_nachname()));
  134. }
  135. }
  136. if (spalten.get(j).equals("P Betreuerin 3")) {
  137. ArrayList<BetreuungFamilie> al = f.getBetreuung();
  138. if (al != null && al.size() >= 3) {
  139. BetreuungFamilie neu = al.get(al.size() - 3);
  140. cell1.setCellValue(new XSSFRichTextString(neu
  141. .getBetreuerin_nummer()
  142. + " "
  143. + neu.getBetreuerin_nachname()));
  144. }
  145. }
  146. if (spalten.get(j).equals("P Betreuerin 4")) {
  147. ArrayList<BetreuungFamilie> al = f.getBetreuung();
  148. if (al != null && al.size() >= 4) {
  149. BetreuungFamilie neu = al.get(al.size() - 4);
  150. cell1.setCellValue(new XSSFRichTextString(neu
  151. .getBetreuerin_nummer()
  152. + " "
  153. + neu.getBetreuerin_nachname()));
  154. }
  155. }
  156. if (spalten.get(j).equals("K1 Nachname")) {
  157. cell1.setCellValue(new XSSFRichTextString(f
  158. .getNachname_kontaktperson1()));
  159. }
  160. if (spalten.get(j).equals("K2 Nachname")) {
  161. cell1.setCellValue(new XSSFRichTextString(f
  162. .getNachname_kontaktperson2()));
  163. }
  164. if (spalten.get(j).equals("P Vorname")) {
  165. cell1.setCellValue(new XSSFRichTextString(f
  166. .getVorname_patient()));
  167. }
  168. if (spalten.get(j).equals("K1 Vorname")) {
  169. cell1.setCellValue(new XSSFRichTextString(f
  170. .getVorname_kontaktperson1()));
  171. }
  172. if (spalten.get(j).equals("K2 Vorname")) {
  173. cell1.setCellValue(new XSSFRichTextString(f
  174. .getVorname_kontaktperson2()));
  175. }
  176. if (spalten.get(j).equals("P Geburtsdatum")) {
  177. cell1.setCellValue(new XSSFRichTextString(f
  178. .getGeburtsdatum_patient()));
  179. }
  180. if (spalten.get(j).equals("K1 Geburtsdatum")) {
  181. cell1.setCellValue(new XSSFRichTextString(f
  182. .getGeburtsdatum_kontaktperson1()));
  183. }
  184. if (spalten.get(j).equals("K2 Geburtsdatum")) {
  185. cell1.setCellValue(new XSSFRichTextString(f
  186. .getGeburtsdatum_kontaktperson2()));
  187. }
  188. if (spalten.get(j).equals("P Adresse")) {
  189. cell1.setCellValue(new XSSFRichTextString(f
  190. .getAdresse_patient()));
  191. }
  192. if (spalten.get(j).equals("K1 Adresse")) {
  193. cell1.setCellValue(new XSSFRichTextString(f
  194. .getAdresse_kontaktperson1()));
  195. }
  196. if (spalten.get(j).equals("K2 Adresse")) {
  197. cell1.setCellValue(new XSSFRichTextString(f
  198. .getAdresse_kontaktperson2()));
  199. }
  200. if (spalten.get(j).equals("P Stadt")) {
  201. cell1.setCellValue(new XSSFRichTextString(f
  202. .getStadt_patient()));
  203. }
  204. if (spalten.get(j).equals("K1 Stadt")) {
  205. cell1.setCellValue(new XSSFRichTextString(f
  206. .getStadt_kontaktperson1()));
  207. }
  208. if (spalten.get(j).equals("K2 Stadt")) {
  209. cell1.setCellValue(new XSSFRichTextString(f
  210. .getStadt_kontaktperson2()));
  211. }
  212. if (spalten.get(j).equals("P PLZ")) {
  213. cell1.setCellValue(new XSSFRichTextString(f
  214. .getPlz_patient()));
  215. }
  216. if (spalten.get(j).equals("K1 PLZ")) {
  217. cell1.setCellValue(new XSSFRichTextString(f
  218. .getPlz_kontaktperson1()));
  219. }
  220. if (spalten.get(j).equals("K2 PLZ")) {
  221. cell1.setCellValue(new XSSFRichTextString(f
  222. .getPlz_kontaktperson2()));
  223. }
  224. if (spalten.get(j).equals("P Email")) {
  225. cell1.setCellValue(new XSSFRichTextString(f
  226. .getEmail_patient()));
  227. }
  228. if (spalten.get(j).equals("K1 Email")) {
  229. cell1.setCellValue(new XSSFRichTextString(f
  230. .getEmail_kontaktperson1()));
  231. }
  232. if (spalten.get(j).equals("K2 Email")) {
  233. cell1.setCellValue(new XSSFRichTextString(f
  234. .getEmail_kontaktperson2()));
  235. }
  236. if (spalten.get(j).equals("P Bundesland")) {
  237. cell1.setCellValue(new XSSFRichTextString(f
  238. .getBunesland_patient()));
  239. }
  240. if (spalten.get(j).equals("K1 Bundesland")) {
  241. cell1.setCellValue(new XSSFRichTextString(f
  242. .getBunesland_kontaktperson1()));
  243. }
  244. if (spalten.get(j).equals("K2 Bundesland")) {
  245. cell1.setCellValue(new XSSFRichTextString(f
  246. .getBunesland_kontaktperson2()));
  247. }
  248. if (spalten.get(j).equals("P Handy")) {
  249. cell1.setCellValue(new XSSFRichTextString(f
  250. .getHandy_patient()));
  251. }
  252. if (spalten.get(j).equals("K1 Handy")) {
  253. cell1.setCellValue(new XSSFRichTextString(f
  254. .getHandy_kontaktperson1()));
  255. }
  256. if (spalten.get(j).equals("K2 Handy")) {
  257. cell1.setCellValue(new XSSFRichTextString(f
  258. .getHandy_kontaktperson2()));
  259. }
  260. if (spalten.get(j).equals("P Festnetz")) {
  261. cell1.setCellValue(new XSSFRichTextString(f
  262. .getFestnetz_patient()));
  263. }
  264. if (spalten.get(j).equals("K1 Festnetz")) {
  265. cell1.setCellValue(new XSSFRichTextString(f
  266. .getFestnetz_kontaktperson1()));
  267. }
  268. if (spalten.get(j).equals("K2 Festnetz")) {
  269. cell1.setCellValue(new XSSFRichTextString(f
  270. .getFestnetz_kontaktperson2()));
  271. }
  272. if (spalten.get(j).equals("P Kontakt")) {
  273. cell1.setCellValue(new XSSFRichTextString(f
  274. .getKontakt()));
  275. }
  276. if (spalten.get(j).equals("P Angefangen")) {
  277. cell1.setCellValue(new XSSFRichTextString(f
  278. .getAngefangen()));
  279. }
  280. if (spalten.get(j).equals("P Hausarzt Name")) {
  281. cell1.setCellValue(new XSSFRichTextString(f
  282. .getHausarzt_name()));
  283. }
  284. if (spalten.get(j).equals("P Hausarzt Telefon")) {
  285. cell1.setCellValue(new XSSFRichTextString(f
  286. .getHausarzt_telefon()));
  287. }
  288. if (spalten.get(j).equals("P Hausarzt Adresse")) {
  289. cell1.setCellValue(new XSSFRichTextString(f
  290. .getHausarzt_adresse()));
  291. }
  292. if (spalten.get(j).equals("P Hausarzt Stadt")) {
  293. cell1.setCellValue(new XSSFRichTextString(f
  294. .getHausarzt_stadt()));
  295. }
  296. if (spalten.get(j).equals("P Hausarzt PLZ")) {
  297. cell1.setCellValue(new XSSFRichTextString(f
  298. .getHausarzt_plz()));
  299. }
  300. if (spalten.get(j).equals("P2 Diagnose")) {
  301. cell1.setCellValue(new XSSFRichTextString(f
  302. .getDiagnosep2()));
  303. }
  304. if (spalten.get(j).equals("P Infos")) {
  305. cell1.setCellValue(new XSSFRichTextString(f.getArea()));
  306. }
  307. if (spalten.get(j).equals("P2 Nachname")) {
  308. cell1.setCellValue(new XSSFRichTextString(f
  309. .getNachname_patient2()));
  310. }
  311. if (spalten.get(j).equals("P2 Vorname")) {
  312. cell1.setCellValue(new XSSFRichTextString(f
  313. .getVorname_patient2()));
  314. }
  315. if (spalten.get(j).equals("P2 Geburtsdatum")) {
  316. cell1.setCellValue(new XSSFRichTextString(f
  317. .getGeburtsdatum_patient2()));
  318. }
  319. if (spalten.get(j).equals("P2 Adresse")) {
  320. cell1.setCellValue(new XSSFRichTextString(f
  321. .getAdresse_patient2()));
  322. }
  323. if (spalten.get(j).equals("P2 Stadt")) {
  324. cell1.setCellValue(new XSSFRichTextString(f
  325. .getStadt_patient2()));
  326. }
  327. if (spalten.get(j).equals("P2 PLZ")) {
  328. cell1.setCellValue(new XSSFRichTextString(f
  329. .getPlz_patient2()));
  330. }
  331. if (spalten.get(j).equals("P2 Bundesland")) {
  332. cell1.setCellValue(new XSSFRichTextString(f
  333. .getBunesland_patient2()));
  334. }
  335. if (spalten.get(j).equals("P2 Handy")) {
  336. cell1.setCellValue(new XSSFRichTextString(f
  337. .getHandy_patient2()));
  338. }
  339. if (spalten.get(j).equals("P2 Festnetz")) {
  340. cell1.setCellValue(new XSSFRichTextString(f
  341. .getFestnetz_patient2()));
  342. }
  343. if (spalten.get(j).equals("P2 Email")) {
  344. cell1.setCellValue(new XSSFRichTextString(f
  345. .getEmail_patient2()));
  346. }
  347. if (spalten.get(j).equals("P2 Angefangen")) {
  348. cell1.setCellValue(new XSSFRichTextString(f
  349. .getAngefangen2()));
  350. }
  351. if (spalten.get(j).equals("P2 Aufgehรถrt")) {
  352. cell1.setCellValue(new XSSFRichTextString(f
  353. .getAufgehort2()));
  354. }
  355. }
  356. }
  357. XSSFRow row = sheet.createRow(1);
  358. if (patient1 == 0) {
  359. if (patient2 == 0) {
  360. if (kontaktperson1 != 0) {
  361. sheet.addMergedRegion(new CellRangeAddress(1, // first
  362. // row
  363. // (0-based)
  364. 1, // last row (0-based)
  365. 0, // first column (0-based)
  366. kontaktperson1 - 1 // last column (0-based)
  367. ));
  368. XSSFCell headerCell1 = row.createCell(0);
  369. headerCell1.setCellStyle(headerStyle);
  370. headerCell1.setCellValue("Kontaktperson 1");
  371. }
  372. if (kontaktperson2 != 0) {
  373. sheet.addMergedRegion(new CellRangeAddress(1, // first
  374. // row
  375. // (0-based)
  376. 1, // last row (0-based)
  377. kontaktperson1, // first column (0-based)
  378. kontaktperson1 + kontaktperson2 - 1 // last
  379. // column
  380. // (0-based)
  381. ));
  382. XSSFCell headerCell6 = row.createCell(kontaktperson1);
  383. headerCell6.setCellStyle(headerStyle);
  384. headerCell6.setCellValue("Kontaktperson 2");
  385. }
  386. } else if (kontaktperson1 == 0) {
  387. if (patient2 != 0) {
  388. sheet.addMergedRegion(new CellRangeAddress(1, // first
  389. // row
  390. // (0-based)
  391. 1, // last row (0-based)
  392. 0, // first column (0-based)
  393. patient2 - 1 // last column (0-based)
  394. ));
  395. XSSFCell headerCell1 = row.createCell(0);
  396. headerCell1.setCellStyle(headerStyle);
  397. headerCell1.setCellValue("Patient 2");
  398. }
  399. if (kontaktperson2 != 0) {
  400. sheet.addMergedRegion(new CellRangeAddress(1, // first
  401. // row
  402. // (0-based)
  403. 1, // last row (0-based)
  404. patient2, // first column (0-based)
  405. patient2 + kontaktperson2 - 1 // last
  406. // column
  407. // (0-based)
  408. ));
  409. XSSFCell headerCell6 = row.createCell(patient2);
  410. headerCell6.setCellStyle(headerStyle);
  411. headerCell6.setCellValue("Kontaktperson 2");
  412. }
  413. } else if (kontaktperson2 == 0) {
  414. if (patient2 != 0) {
  415. sheet.addMergedRegion(new CellRangeAddress(1, 1, 0,
  416. patient2 - 1));
  417. XSSFCell headerCell1 = row.createCell(0);
  418. headerCell1.setCellStyle(headerStyle);
  419. headerCell1.setCellValue("Patient 2");
  420. }
  421. if (kontaktperson1 != 0) {
  422. sheet.addMergedRegion(new CellRangeAddress(1, // first
  423. // row
  424. // (0-based)
  425. 1, // last row (0-based)
  426. patient2, // first column (0-based)
  427. patient2 + kontaktperson1 - 1 // last
  428. // column
  429. // (0-based)
  430. ));
  431. XSSFCell headerCell6 = row.createCell(patient2);
  432. headerCell6.setCellStyle(headerStyle);
  433. headerCell6.setCellValue("Kontaktperson 1");
  434. }
  435. } else {
  436. sheet.addMergedRegion(new CellRangeAddress(1, 1, 0,
  437. patient2 - 1));
  438. XSSFCell headerCell1 = row.createCell(0);
  439. headerCell1.setCellStyle(headerStyle);
  440. headerCell1.setCellValue("Patient 2");
  441. sheet.addMergedRegion(new CellRangeAddress(1, 1, patient2,
  442. patient2 + kontaktperson1 - 1));
  443. XSSFCell headerCell2 = row.createCell(patient2);
  444. headerCell2.setCellStyle(headerStyle);
  445. headerCell2.setCellValue("Kontaktperson 1");
  446. sheet.addMergedRegion(new CellRangeAddress(1, 1, patient2
  447. + kontaktperson1, patient2 + kontaktperson1
  448. + kontaktperson2 - 1));
  449. XSSFCell headerCell3 = row.createCell(patient2
  450. + kontaktperson1);
  451. headerCell3.setCellStyle(headerStyle);
  452. headerCell3.setCellValue("Kontaktperson 2");
  453. }
  454. } else if (patient2 == 0) {
  455. if (patient1 == 0) {
  456. if (kontaktperson1 != 0) {
  457. sheet.addMergedRegion(new CellRangeAddress(1, // first
  458. // row
  459. // (0-based)
  460. 1, // last row (0-based)
  461. 0, // first column (0-based)
  462. kontaktperson1 - 1 // last column (0-based)
  463. ));
  464. XSSFCell headerCell1 = row.createCell(0);
  465. headerCell1.setCellStyle(headerStyle);
  466. headerCell1.setCellValue("Kontaktperson 1");
  467. }
  468. if (kontaktperson2 != 0) {
  469. sheet.addMergedRegion(new CellRangeAddress(1, // first
  470. // row
  471. // (0-based)
  472. 1, // last row (0-based)
  473. kontaktperson1, // first column (0-based)
  474. kontaktperson1 + kontaktperson2 - 1 // last
  475. // column
  476. // (0-based)
  477. ));
  478. XSSFCell headerCell6 = row.createCell(kontaktperson1);
  479. headerCell6.setCellStyle(headerStyle);
  480. headerCell6.setCellValue("Kontaktperson 2");
  481. }
  482. } else if (kontaktperson1 == 0) {
  483. if (patient1 != 0) {
  484. sheet.addMergedRegion(new CellRangeAddress(1, // first
  485. // row
  486. // (0-based)
  487. 1, // last row (0-based)
  488. 0, // first column (0-based)
  489. patient1 - 1 // last column (0-based)
  490. ));
  491. XSSFCell headerCell1 = row.createCell(0);
  492. headerCell1.setCellStyle(headerStyle);
  493. headerCell1.setCellValue("Patient 1");
  494. }
  495. if (kontaktperson2 != 0) {
  496. sheet.addMergedRegion(new CellRangeAddress(1, // first
  497. // row
  498. // (0-based)
  499. 1, // last row (0-based)
  500. patient1, // first column (0-based)
  501. patient1 + kontaktperson2 - 1 // last
  502. // column
  503. // (0-based)
  504. ));
  505. XSSFCell headerCell6 = row.createCell(patient1);
  506. headerCell6.setCellStyle(headerStyle);
  507. headerCell6.setCellValue("Kontaktperson 2");
  508. }
  509. } else if (kontaktperson2 == 0) {
  510. if (patient1 != 0) {
  511. sheet.addMergedRegion(new CellRangeAddress(1, 1, 0,
  512. patient1 - 1));
  513. XSSFCell headerCell1 = row.createCell(0);
  514. headerCell1.setCellStyle(headerStyle);
  515. headerCell1.setCellValue("Patient 1");
  516. }
  517. if (kontaktperson1 != 0) {
  518. sheet.addMergedRegion(new CellRangeAddress(1, // first
  519. // row
  520. // (0-based)
  521. 1, // last row (0-based)
  522. patient1, // first column (0-based)
  523. patient1 + kontaktperson1 - 1 // last
  524. // column
  525. // (0-based)
  526. ));
  527. XSSFCell headerCell6 = row.createCell(patient1);
  528. headerCell6.setCellStyle(headerStyle);
  529. headerCell6.setCellValue("Kontaktperson 1");
  530. }
  531. } else {
  532. sheet.addMergedRegion(new CellRangeAddress(1, 1, 0,
  533. patient1 - 1));
  534. XSSFCell headerCell1 = row.createCell(0);
  535. headerCell1.setCellStyle(headerStyle);
  536. headerCell1.setCellValue("Patient 1");
  537. sheet.addMergedRegion(new CellRangeAddress(1, 1, patient1,
  538. patient1 + kontaktperson1 - 1));
  539. XSSFCell headerCell2 = row.createCell(patient1);
  540. headerCell2.setCellStyle(headerStyle);
  541. headerCell2.setCellValue("Kontaktperson 1");
  542. sheet.addMergedRegion(new CellRangeAddress(1, 1, patient1
  543. + kontaktperson1, patient1 + kontaktperson1
  544. + kontaktperson2 - 1));
  545. XSSFCell headerCell3 = row.createCell(patient1
  546. + kontaktperson1);
  547. headerCell3.setCellStyle(headerStyle);
  548. headerCell3.setCellValue("Kontaktperson 2");
  549. }
  550. } else if (kontaktperson1 == 0) {
  551. if (patient1 == 0) {
  552. if (patient2 != 0) {
  553. sheet.addMergedRegion(new CellRangeAddress(1, // first
  554. // row
  555. // (0-based)
  556. 1, // last row (0-based)
  557. 0, // first column (0-based)
  558. patient2 - 1 // last column (0-based)
  559. ));
  560. XSSFCell headerCell1 = row.createCell(0);
  561. headerCell1.setCellStyle(headerStyle);
  562. headerCell1.setCellValue("Patient 2");
  563. }
  564. if (kontaktperson2 != 0) {
  565. sheet.addMergedRegion(new CellRangeAddress(1, // first
  566. // row
  567. // (0-based)
  568. 1, // last row (0-based)
  569. patient2, // first column (0-based)
  570. patient2 + kontaktperson2 - 1 // last
  571. // column
  572. // (0-based)
  573. ));
  574. XSSFCell headerCell6 = row.createCell(patient2);
  575. headerCell6.setCellStyle(headerStyle);
  576. headerCell6.setCellValue("Kontaktperson 2");
  577. }
  578. } else if (patient2 == 0) {
  579. if (patient1 != 0) {
  580. sheet.addMergedRegion(new CellRangeAddress(1, // first
  581. // row
  582. // (0-based)
  583. 1, // last row (0-based)
  584. 0, // first column (0-based)
  585. patient1 - 1 // last column (0-based)
  586. ));
  587. XSSFCell headerCell1 = row.createCell(0);
  588. headerCell1.setCellStyle(headerStyle);
  589. headerCell1.setCellValue("Patient 1");
  590. }
  591. if (kontaktperson2 != 0) {
  592. sheet.addMergedRegion(new CellRangeAddress(1, // first
  593. // row
  594. // (0-based)
  595. 1, // last row (0-based)
  596. patient1, // first column (0-based)
  597. patient1 + kontaktperson2 - 1 // last
  598. // column
  599. // (0-based)
  600. ));
  601. XSSFCell headerCell6 = row.createCell(patient1);
  602. headerCell6.setCellStyle(headerStyle);
  603. headerCell6.setCellValue("Kontaktperson 2");
  604. }
  605. } else if (kontaktperson2 == 0) {
  606. if (patient1 != 0) {
  607. sheet.addMergedRegion(new CellRangeAddress(1, 1, 0,
  608. patient1 - 1));
  609. XSSFCell headerCell1 = row.createCell(0);
  610. headerCell1.setCellStyle(headerStyle);
  611. headerCell1.setCellValue("Patient 1");
  612. }
  613. if (patient2 != 0) {
  614. sheet.addMergedRegion(new CellRangeAddress(1, // first
  615. // row
  616. // (0-based)
  617. 1, // last row (0-based)
  618. patient1, // first column (0-based)
  619. patient1 + patient2 - 1 // last
  620. // column
  621. // (0-based)
  622. ));
  623. XSSFCell headerCell6 = row.createCell(patient1);
  624. headerCell6.setCellStyle(headerStyle);
  625. headerCell6.setCellValue("Patient 2");
  626. }
  627. } else {
  628. sheet.addMergedRegion(new CellRangeAddress(1, 1, 0,
  629. patient1 - 1));
  630. XSSFCell headerCell1 = row.createCell(0);
  631. headerCell1.setCellStyle(headerStyle);
  632. headerCell1.setCellValue("Patient 1");
  633. sheet.addMergedRegion(new CellRangeAddress(1, 1, patient1,
  634. patient1 + patient2 - 1));
  635. XSSFCell headerCell2 = row.createCell(patient1);
  636. headerCell2.setCellStyle(headerStyle);
  637. headerCell2.setCellValue("Patient 2");
  638. sheet.addMergedRegion(new CellRangeAddress(1, 1, patient1
  639. + patient2, patient1 + patient2 + kontaktperson2
  640. - 1));
  641. XSSFCell headerCell3 = row.createCell(patient1 + patient2);
  642. headerCell3.setCellStyle(headerStyle);
  643. headerCell3.setCellValue("Kontaktperson 2");
  644. }
  645. } else if (kontaktperson2 == 0) {
  646. if (patient1 == 0) {
  647. if (patient2 != 0) {
  648. sheet.addMergedRegion(new CellRangeAddress(1, // first
  649. // row
  650. // (0-based)
  651. 1, // last row (0-based)
  652. 0, // first column (0-based)
  653. patient2 - 1 // last column (0-based)
  654. ));
  655. XSSFCell headerCell1 = row.createCell(0);
  656. headerCell1.setCellStyle(headerStyle);
  657. headerCell1.setCellValue("Patient 2");
  658. }
  659. if (kontaktperson1 != 0) {
  660. sheet.addMergedRegion(new CellRangeAddress(1, // first
  661. // row
  662. // (0-based)
  663. 1, // last row (0-based)
  664. patient2, // first column (0-based)
  665. patient2 + kontaktperson1 - 1 // last
  666. // column
  667. // (0-based)
  668. ));
  669. XSSFCell headerCell6 = row.createCell(patient2);
  670. headerCell6.setCellStyle(headerStyle);
  671. headerCell6.setCellValue("Kontaktperson 1");
  672. }
  673. } else if (patient2 == 0) {
  674. if (patient1 != 0) {
  675. sheet.addMergedRegion(new CellRangeAddress(1, // first
  676. // row
  677. // (0-based)
  678. 1, // last row (0-based)
  679. 0, // first column (0-based)
  680. patient1 - 1 // last column (0-based)
  681. ));
  682. XSSFCell headerCell1 = row.createCell(0);
  683. headerCell1.setCellStyle(headerStyle);
  684. headerCell1.setCellValue("Patient 1");
  685. }
  686. if (kontaktperson1 != 0) {
  687. sheet.addMergedRegion(new CellRangeAddress(1, // first
  688. // row
  689. // (0-based)
  690. 1, // last row (0-based)
  691. patient1, // first column (0-based)
  692. patient1 + kontaktperson1 - 1 // last
  693. // column
  694. // (0-based)
  695. ));
  696. XSSFCell headerCell6 = row.createCell(patient1);
  697. headerCell6.setCellStyle(headerStyle);
  698. headerCell6.setCellValue("Kontaktperson 1");
  699. }
  700. } else if (kontaktperson1 == 0) {
  701. if (patient1 != 0) {
  702. sheet.addMergedRegion(new CellRangeAddress(1, 1, 0,
  703. patient1 - 1));
  704. XSSFCell headerCell1 = row.createCell(0);
  705. headerCell1.setCellStyle(headerStyle);
  706. headerCell1.setCellValue("Patient 1");
  707. }
  708. if (patient2 != 0) {
  709. sheet.addMergedRegion(new CellRangeAddress(1, // first
  710. // row
  711. // (0-based)
  712. 1, // last row (0-based)
  713. patient1, // first column (0-based)
  714. patient1 + patient2 - 1 // last
  715. // column
  716. // (0-based)
  717. ));
  718. XSSFCell headerCell6 = row.createCell(patient1);
  719. headerCell6.setCellStyle(headerStyle);
  720. headerCell6.setCellValue("Patient 2");
  721. }
  722. } else {
  723. sheet.addMergedRegion(new CellRangeAddress(1, 1, 0,
  724. patient1 - 1));
  725. XSSFCell headerCell1 = row.createCell(0);
  726. headerCell1.setCellStyle(headerStyle);
  727. headerCell1.setCellValue("Patient 1");
  728. sheet.addMergedRegion(new CellRangeAddress(1, 1, patient1,
  729. patient1 + patient2 - 1));
  730. XSSFCell headerCell2 = row.createCell(patient1);
  731. headerCell2.setCellStyle(headerStyle);
  732. headerCell2.setCellValue("Patient 2");
  733. sheet.addMergedRegion(new CellRangeAddress(1, 1, patient1
  734. + patient2, patient1 + patient2 + kontaktperson1
  735. - 1));
  736. XSSFCell headerCell3 = row.createCell(patient1 + patient2);
  737. headerCell3.setCellStyle(headerStyle);
  738. headerCell3.setCellValue("Kontaktperson 1");
  739. }
  740. } else {
  741. sheet.addMergedRegion(new CellRangeAddress(1, 1, 0,
  742. patient1 - 1));
  743. XSSFCell headerCell1 = row.createCell(0);
  744. headerCell1.setCellStyle(headerStyle);
  745. headerCell1.setCellValue("Patient 1");
  746. sheet.addMergedRegion(new CellRangeAddress(1, 1, patient1,
  747. patient1 + patient2 - 1));
  748. XSSFCell headerCell2 = row.createCell(patient1);
  749. headerCell2.setCellStyle(headerStyle);
  750. headerCell2.setCellValue("Patient 2");
  751. sheet.addMergedRegion(new CellRangeAddress(1, 1, patient1
  752. + patient2, patient1 + patient2 + kontaktperson1 - 1));
  753. XSSFCell headerCell3 = row.createCell(patient1 + patient2);
  754. headerCell3.setCellStyle(headerStyle);
  755. headerCell3.setCellValue("Kontaktperson 1");
  756. sheet.addMergedRegion(new CellRangeAddress(1, 1, patient1
  757. + patient2 + kontaktperson1, patient1 + patient2
  758. + kontaktperson1 + kontaktperson2 - 1));
  759. XSSFCell headerCell4 = row.createCell(patient1 + patient2
  760. + kontaktperson1);
  761. headerCell4.setCellStyle(headerStyle);
  762. headerCell4.setCellValue("Kontaktperson 2");
  763. }
  764. for (int i = 0; i <= spalten.size() + 1; i++) {
  765. sheet.autoSizeColumn(i);
  766. }
  767. // write in excel
  768. xssfWorkbook.write(fileOutputStream);
  769. } catch (Exception e) {
  770. e.printStackTrace();
  771. } finally {
  772. /*
  773. * Close File Output Stream
  774. */
  775. try {
  776. if (fileOutputStream != null) {
  777. fileOutputStream.close();
  778. }
  779. } catch (IOException ex) {
  780. ex.printStackTrace();
  781. }
  782. }
  783. }
  784. }