ryoakg
9/9/2017 - 5:57 PM

poi-write-xlsx.clj

(set-env! :dependencies '[;; https://mvnrepository.com/artifact/org.apache.poi/poi
                          [org.apache.poi/poi "3.16"]
                          ;; https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml
                          [org.apache.poi/poi-ooxml "3.16"]])

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

(import '(org.apache.poi.xssf.usermodel XSSFWorkbook)
        '(org.apache.poi.ss.usermodel Workbook Sheet Row Cell))

(let [^Workbook wb (XSSFWorkbook.)
      ^Sheet sheet (.createSheet wb "Sheet1")]
  (dotimes [i 5]
    (let [^Row row (.createRow sheet i)]
      (dotimes [j 5]
        (let [^Cell cell (.createCell row j)]
          (.setCellValue cell (str "Cell " i " " j))))))
  (with-open [os (io/output-stream (io/file "test.xlsx"))]
    (.write wb os)))