Skip to content

Instantly share code, notes, and snippets.

@damesek
Last active October 7, 2021 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damesek/e97a5fd28c87bf590e18a307f2d21b0f to your computer and use it in GitHub Desktop.
Save damesek/e97a5fd28c87bf590e18a307f2d21b0f to your computer and use it in GitHub Desktop.
Write xlsx/ xlsm (template) files from clojure without style or macro loss
(ns playground
(:require [libpython-clj2.python :as py]
[libpython-clj2.require :refer [require-python]]))
(require '[libpython-clj2.python
:refer [as-python as-jvm
->python ->jvm
get-attr call-attr call-attr-kw
get-item
initialize!
run-simple-string
add-module module-dict
import-module
python-type]])
(initialize!)
; pip install editpyxl
(require-python '[editpyxl :refer [Workbook]])
(defn write-cell-newfile [file nloc cell cell-val]
"new file created from old
without style/ vba macro loss"
(let [wb (Workbook)]
(call-attr wb "open" file)
(let [ws (get-item wb "your-sheet-name")]
(py/set-item! ws cell cell-val)
(call-attr wb "save" nloc)
(call-attr wb "close"))))
(write-cell-newfile
"orginal-template.xlsm"
"new-file.xlsm"
"V8" 777)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment