Skip to content

Commit 4a873ec

Browse files
committed
Add a second arity to tree-grid to specify column order
1 parent 2ed04d0 commit 4a873ec

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/excel_clj/core.clj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,15 @@
163163
(defn tree-grid
164164
"Build a lazy sheet grid from `tree`, whose leaves are shaped key->number.
165165
166-
E.g. (tree {:assets {:cash {:usd 100 :eur 100}}})
166+
E.g. (tree-grid {:assets {:cash {:usd 100 :eur 100}}})
167167
168168
See the comment form below this definition for examples."
169-
[tree]
170-
(let [ks (into [""] (keys (tree/fold + tree)))]
171-
(table-grid ks (tree->rows tree))))
169+
([tree]
170+
(let [ks (into [""] (keys (tree/fold + tree)))]
171+
(tree-grid ks tree)))
172+
([ks tree]
173+
(let [ks (into [""] (remove #{""}) ks)] ;; force the "" col to come first
174+
(table-grid ks (tree->rows tree)))))
172175

173176

174177
(comment

test/excel_clj/core_test.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
(let [temp-file (io/file (temp ".xlsx"))]
4242
(try
4343
(testing "Example code snippet writes successfully."
44+
(println "Writing example workbook...")
4445
(write! example-workbook-data temp-file))
4546
(finally
4647
(io/delete-file temp-file)))))
@@ -50,6 +51,7 @@
5051
(let [temp-file (io/file (temp ".xlsx"))]
5152
(try
5253
(testing "Example code snippet writes successfully."
54+
(println "Writing example template...")
5355
(let [template (clojure.java.io/resource "uptime-template.xlsx")
5456
new-data {"raw" (table-grid example-template-data)}]
5557
(append! new-data template "filled-in-template.xlsx")))

0 commit comments

Comments
 (0)