File tree Expand file tree Collapse file tree 3 files changed +35
-18
lines changed Expand file tree Collapse file tree 3 files changed +35
-18
lines changed Original file line number Diff line number Diff line change 28
28
; ;; Build grids of [[cell]] out of Clojure's data structures
29
29
30
30
31
+ (defn- name ' [x]
32
+ (if (instance? Named x)
33
+ (name x)
34
+ (str x)))
35
+
36
+
31
37
(defn best-guess-cell-format
32
38
" Try to guess appropriate formatting based on column name and cell value."
33
39
[val column-name]
34
- (let [column' (string/lower-case
35
- (if (instance? Named column-name)
36
- (name column-name)
37
- (str column-name)))]
40
+ (let [column' (string/lower-case (name' column-name))]
38
41
(cond
39
42
(and (string? val) (> (count val) 75 ))
40
43
{:wrap-text true }
146
149
empty-row (zipmap (keys combined) (repeat nil ))]
147
150
(concat
148
151
; header
149
- [(style (assoc empty-row " " (name parent)) (get' fmts depth))]
152
+ [(style (assoc empty-row " " (name' parent)) (get' fmts depth))]
150
153
; children
151
154
(tree/table render node)
152
155
; total row
153
156
(when (> (count node) 1 )
154
157
[(style-data (assoc combined " " " " ) (get' total-fmts depth))])))
155
158
; leaf
156
- [(style-data (assoc node " " (name parent)) (get' fmts (max depth 2 )))]))
159
+ [(style-data (assoc node " " (name' parent)) (get' fmts (max depth 2 )))]))
157
160
t)))
158
161
159
162
371
374
; ; Some v1.X backwards compatibility
372
375
373
376
374
- (def ^:deprecated tree (partial deprecated/tree table-grid with-title))
375
- (def ^:deprecated table deprecated /table )
376
- (def ^:deprecated quick-open quick-open! )
377
+ (def ^:deprecated tree
378
+ " Deprecated in favor of `tree-grid`."
379
+ (partial deprecated/tree table-grid with-title))
380
+
381
+
382
+ (def ^:deprecated table
383
+ " Deprecated in favor of `table-grid`."
384
+ deprecated /table )
385
+
386
+
387
+ (def ^:deprecated quick-open
388
+ " Deprecated in favor of `quick-open!`."
389
+ quick-open! )
377
390
378
391
379
392
(comment
Original file line number Diff line number Diff line change 4
4
See the `example` and `performance-test` functions at the end of
5
5
this ns + the adjacent (comment ...) forms for more detail."
6
6
{:author " Matthew Downey" }
7
- (:require [clojure.java.io :as io ]
8
- [taoensso.encore :as enc]
9
- [excel-clj.style :as style ]
7
+ (:require [excel-clj.style :as style ]
8
+
9
+ [clojure.java.io :as io ]
10
10
[clojure.walk :as walk]
11
+
12
+ [taoensso.encore :as enc]
11
13
[taoensso.tufte :as tufte])
12
14
(:import (java.io Closeable BufferedInputStream InputStream)
13
15
(org.apache.poi.ss.usermodel RichTextString Sheet Cell Row Workbook)
Original file line number Diff line number Diff line change 3
3
4
4
Use ordered maps (like array-map) to enforce order."
5
5
{:author " Matthew Downey" }
6
- (:require [clojure.walk :as walk]))
6
+ (:require [clojure.walk :as walk])
7
+ (:import (clojure.lang Named)))
7
8
8
9
9
10
(defn leaf?
97
98
98
99
99
100
(def ^{:private true :dynamic true } *depth* nil )
101
+ (defn- ->str [x] (if (instance? Named x) (name x) (str x)))
100
102
(defn table
101
103
" Given `(fn f [parent-key node depth] => row-map)`, convert `tree` into a
102
104
table of `[row]`.
112
114
(fn render [parent node depth]
113
115
(let [row (fold (fn [_ _] nil ) node)]
114
116
(cons
115
- (assoc row " " (name parent) :tree/indent depth)
117
+ (assoc row " " (->str parent) :tree/indent depth)
116
118
(when-not (leaf? node) (table render node)))))
117
119
tree))
118
120
([f tree]
131
133
(cons
132
134
(assoc
133
135
(combine-with node)
134
- " " (name parent)
136
+ " " (->str parent)
135
137
:tree/indent depth)
136
138
(when-not (leaf? node) (table render node))))))
137
139
147
149
(let [combined (combine-with node)
148
150
empty-row (zipmap (keys combined) (repeat nil ))]
149
151
(concat
150
- [(assoc empty-row " " (name parent) :tree/indent depth)] ; header
152
+ [(assoc empty-row " " (->str parent) :tree/indent depth)] ; header
151
153
(table render node) ; children
152
154
[(assoc combined " " " " :tree/indent depth)])) ; total
153
- [(assoc node " " (name parent) :tree/indent depth)]))))
155
+ [(assoc node " " (->str parent) :tree/indent depth)]))))
154
156
155
157
156
158
(defn indent
275
277
(fold - {:assets (fold + assets)
276
278
:liabilities (fold + liabilities)})}))))
277
279
278
- (print-table tbl))
280
+ (print-table tbl))
You can’t perform that action at this time.
0 commit comments