Liking cljdoc? Tell your friends :D

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

NamespacePurpose

wagoe.reports.core.report

Pure helpers: formatting, section rendering, report preparation

wagoe.reports.shell.registry

defreport macro and the definition registry

wagoe.reports.ports

ReportServiceProtocol — what apps call on (ig/ref :wagoe/reports); ReportGeneratorProtocol — what adapters implement

wagoe.reports.schema

Malli schemas: ColumnDef, SectionDef, ReportDefinition, ReportOutput

wagoe.reports.shell.adapters.pdf

OpenHTMLtoPDF adapter — Hiccup → HTML → PDF bytes

wagoe.reports.shell.adapters.excel

docjure adapter — column defs + data → XLSX bytes

wagoe.reports.shell.adapters.word

Apache POI XWPF adapter — sections → DOCX bytes

wagoe.reports.shell.adapters.csv

RFC 4180 CSV from the first :table section, formula cells neutralised

wagoe.reports.shell.service

ReportService, the :wagoe/reports component

wagoe.reports.shell.jobs-integration

The :reports/generate job: generate, then store and mail

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

Can you improve this documentation? These fine people already did:
Thijs Creemers & thijscreemers
Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close