Skip to content

Commit 2ed04d0

Browse files
committed
Fix ClassCastException issue from uses of name
1 parent 0817cb9 commit 2ed04d0

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

src/excel_clj/core.clj

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@
2828
;;; Build grids of [[cell]] out of Clojure's data structures
2929

3030

31+
(defn- name' [x]
32+
(if (instance? Named x)
33+
(name x)
34+
(str x)))
35+
36+
3137
(defn best-guess-cell-format
3238
"Try to guess appropriate formatting based on column name and cell value."
3339
[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))]
3841
(cond
3942
(and (string? val) (> (count val) 75))
4043
{:wrap-text true}
@@ -146,14 +149,14 @@
146149
empty-row (zipmap (keys combined) (repeat nil))]
147150
(concat
148151
; header
149-
[(style (assoc empty-row "" (name parent)) (get' fmts depth))]
152+
[(style (assoc empty-row "" (name' parent)) (get' fmts depth))]
150153
; children
151154
(tree/table render node)
152155
; total row
153156
(when (> (count node) 1)
154157
[(style-data (assoc combined "" "") (get' total-fmts depth))])))
155158
; 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)))]))
157160
t)))
158161

159162

@@ -371,9 +374,19 @@
371374
;; Some v1.X backwards compatibility
372375

373376

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!)
377390

378391

379392
(comment

src/excel_clj/poi.clj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
See the `example` and `performance-test` functions at the end of
55
this ns + the adjacent (comment ...) forms for more detail."
66
{: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]
1010
[clojure.walk :as walk]
11+
12+
[taoensso.encore :as enc]
1113
[taoensso.tufte :as tufte])
1214
(:import (java.io Closeable BufferedInputStream InputStream)
1315
(org.apache.poi.ss.usermodel RichTextString Sheet Cell Row Workbook)

src/excel_clj/tree.clj

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
44
Use ordered maps (like array-map) to enforce order."
55
{:author "Matthew Downey"}
6-
(:require [clojure.walk :as walk]))
6+
(:require [clojure.walk :as walk])
7+
(:import (clojure.lang Named)))
78

89

910
(defn leaf?
@@ -97,6 +98,7 @@
9798

9899

99100
(def ^{:private true :dynamic true} *depth* nil)
101+
(defn- ->str [x] (if (instance? Named x) (name x) (str x)))
100102
(defn table
101103
"Given `(fn f [parent-key node depth] => row-map)`, convert `tree` into a
102104
table of `[row]`.
@@ -112,7 +114,7 @@
112114
(fn render [parent node depth]
113115
(let [row (fold (fn [_ _] nil) node)]
114116
(cons
115-
(assoc row "" (name parent) :tree/indent depth)
117+
(assoc row "" (->str parent) :tree/indent depth)
116118
(when-not (leaf? node) (table render node)))))
117119
tree))
118120
([f tree]
@@ -131,7 +133,7 @@
131133
(cons
132134
(assoc
133135
(combine-with node)
134-
"" (name parent)
136+
"" (->str parent)
135137
:tree/indent depth)
136138
(when-not (leaf? node) (table render node))))))
137139

@@ -147,10 +149,10 @@
147149
(let [combined (combine-with node)
148150
empty-row (zipmap (keys combined) (repeat nil))]
149151
(concat
150-
[(assoc empty-row "" (name parent) :tree/indent depth)] ; header
152+
[(assoc empty-row "" (->str parent) :tree/indent depth)] ; header
151153
(table render node) ; children
152154
[(assoc combined "" "" :tree/indent depth)])) ; total
153-
[(assoc node "" (name parent) :tree/indent depth)]))))
155+
[(assoc node "" (->str parent) :tree/indent depth)]))))
154156

155157

156158
(defn indent
@@ -275,4 +277,4 @@
275277
(fold - {:assets (fold + assets)
276278
:liabilities (fold + liabilities)})}))))
277279

278-
(print-table tbl))
280+
(print-table tbl))

0 commit comments

Comments
 (0)