reports
PDF, Excel (XLSX), Word (DOCX) and CSV report generation with Hiccup-style templates
and declarative sections. Saves 5–8 days of boilerplate per project.
Supports sync generation and optional async via wagoe-jobs.
Key namespaces
| Namespace | Purpose |
|---|---|
|
Pure helpers: formatting, section rendering, report preparation |
|
|
|
|
|
Malli schemas: |
|
OpenHTMLtoPDF adapter — Hiccup → HTML → PDF bytes |
|
docjure adapter — column defs + data → XLSX bytes |
|
Apache POI XWPF adapter — sections → DOCX bytes |
|
RFC 4180 CSV from the first |
|
|
|
The |
PDF report
;; svc is the :wagoe/reports component: (ig/ref :wagoe/reports)
(require '[wagoe.reports.shell.registry :as r]
'[wagoe.reports.ports :as reports])
(r/defreport invoice-report
{:id :invoice-report
:type :pdf
:page-size :a4
:filename "invoice.pdf"
;; generate passes its opts here; the result is the template's data
:data-source (fn [{:keys [invoice-id]}] (load-invoice invoice-id))
:template (fn [data]
[:html
[:head [:title "Invoice"]]
[:body
[:h1 "Invoice #" (:invoice-number data)]
[:table
[:thead [:tr [:th "Item"] [:th "Amount"]]]
[:tbody
(for [line (:lines data)]
[:tr [:td (:description line)]
[:td (str "€ " (:amount line))]])]]]])})
(def output (reports/generate svc invoice-report {:invoice-id 42}))
;=> {:bytes #bytes[...] :type :pdf :filename "invoice.pdf"}
Excel report
(r/defreport users-export
{:id :users-export
:type :excel
:filename "users.xlsx"
:data-source (fn [_opts] (list-all-users)) ; a seq of row maps
:sections [{:type :table
:columns [{:key :name :label "Name"}
{:key :email :label "Email"}
{:key :role :label "Role"}]}]})
(reports/generate svc users-export {})
Async generation
;; Needs :wagoe/jobs. Only the id travels, so the report must be registered.
(reports/generate-async svc :invoice-report
{:invoice-id 42
:storage-key "invoices" ; needs :wagoe/storage
:notify-email "billing@example.com"}) ; needs :wagoe/email
;=> job id
Testing
clojure -M:test :reports