Last active
October 7, 2021 07:51
-
-
Save damesek/e97a5fd28c87bf590e18a307f2d21b0f to your computer and use it in GitHub Desktop.
Write xlsx/ xlsm (template) files from clojure without style or macro loss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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