Skip to content

Instantly share code, notes, and snippets.

@BadUncleX
Last active April 11, 2018 02:21

Revisions

  1. BadUncleX renamed this gist Apr 11, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. BadUncleX revised this gist Apr 11, 2018. No changes.
  3. BadUncleX created this gist Apr 9, 2018.
    24 changes: 24 additions & 0 deletions jxls.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    :dependencies [[org.clojure/clojure "1.8.0"]
    [org.jxls/jxls "2.4.2"]
    [org.jxls/jxls-poi "1.0.13" :exclusions [org.jxls/jxls]]])

    (import [org.jxls.util JxlsHelper])
    (import [org.jxls.common Context])

    (require '(clojure.java [io :as io]))

    ;; http://jxls.sourceforge.net/xls/object_collection_template.xls
    (def io (io/input-stream "object_collection_template.xls"))
    (def os (io/output-stream "out.xls"))

    ;; keys and values must be strings, yhey are formatted as per template.
    (def employees [ { "name" "Kris" } { "name" "Chris" } ])

    (def context (Context.))
    (.putVar context "employees" employees)

    (def helper (JxlsHelper/getInstance))

    (.processTemplate helper io os context)

    ;; If you try and do `.processTemplate` twice with the same io streams you get `java.lang.IllegalStateException: Cannot load XLS transformer. Please make sure a Transformer implementation is in classpath`.