#125: IHKExporter.java

plugins/org.projectforge.plugins.ihk/src/main/java/org/projectforge/plugins/ihk/IHKExporter.java Path: plugins/...ihk/src/main/java/.../IHKExporter.java · Lines: 292 · Type: Java Excel export engine 292 lines · 201 code · 39 comments · 52 blank

Excel report generator for IHK apprenticeship weekly reports. The core logic of the plugin — takes a week's timesheet entries, the trainee's configuration (IHKCommentObject), and a Merlin Excel template, and produces a formatted IHK-compliant .xlsx file. 292 lines of Java.

Architecture

Uses Merlin (Micromata's Excel templating engine, see #221+) — loads an .xlsx template from the classpath (ClassPathResource("merlin/ihk/ihk.xlsx")), fills in data programmatically, and returns a ByteArrayOutputStream for download.

Key data flows

  1. Training year calculation: Period.between(ausbildungsbeginn, now).getYears() → auto-calculates the training year unless ausbildungsjahr is manually set
  2. Timesheet filtering: queries TimesheetDO for the trainee's entries in the selected week, grouped by day
  3. Hours aggregation: sums work hours per day, formats with DecimalFormat("0.00")
  4. Excel population via Merlin:
    • Reads template workbook from merlin/ihk/ihk.xlsx
    • Fills header: trainee name, department (teamname), training year, calendar week, date range
    • Fills daily rows: day of week, date, topic/activity description from timesheet, hours worked, signature placeholders
    • Applies cell formatting: borders, font sizes, merged cells for header block
  5. Output: writes the populated workbook to a ByteArrayOutputStream, returns the byte array for HTTP download with filename Berichtsheft_KW{week}_{name}.xlsx

Excel template structure

The IHK requires a specific report format containing:

The Merlin template (ihk.xlsx) contains these structural elements; the exporter fills in the dynamic data.

Dependencies