Skip to content

Commit aad00d3

Browse files
committed
Merge branch 'develop' for v1.1.0
2 parents ea4d468 + 30d9d8e commit aad00d3

File tree

9 files changed

+294
-210
lines changed

9 files changed

+294
-210
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Log
22

3+
## [1.1.0] - 2019-05-28
4+
### Added
5+
- More flexible tree rendering/aggregation
6+
7+
### Changed
8+
- Replaced lots of redundant tree code with a `walk` function
9+
310
## [1.0.0] - 2019-04-17
411
### Added
512
- PDF generation

README.md

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ common sense styling.
88

99
Lein:
1010
```
11-
[org.clojars.mjdowney/excel-clj "1.0.0"]
11+
[org.clojars.mjdowney/excel-clj "1.1.0"]
1212
```
1313

1414
- [Getting Started](#getting-started)
@@ -92,6 +92,30 @@ the balances corresponding to an account hierarchy.
9292

9393
![An excel sheet is opened](resources/quick-open-tree.png)
9494

95+
Trees are pretty flexible — the only requirement that we impose is that their
96+
leaves have the format `[string-label, map-of-numbers]`. We construct trees
97+
using the same arguments we'd give to `clojure.core/tree-seq`, plus a walk
98+
function.
99+
100+
We could make a tree for some part of our file system for example:
101+
102+
```clojure
103+
(require '[excel-clj.tree :as tree] '[clojure.java.io :as io])
104+
=> nil
105+
106+
(let [src-tree
107+
(tree/walk
108+
(fn [f xs]
109+
(if-not (seq xs)
110+
[(.getName f) {:size (.length f)}]
111+
[(str (.getName f) "/") xs]))
112+
#(.isDirectory %) #(.listFiles %) (io/file "."))]
113+
(excel/quick-open
114+
{"Source Tree" (excel/tree ["Source" [src-tree]] :data-format :number)}))
115+
```
116+
117+
![An excel sheet is opened](resources/file-tree.png)
118+
95119

96120
### PDF Generation
97121

@@ -188,11 +212,6 @@ that includes optional style data / cell merging instructions.
188212
![A spreadsheet with a merged title](resources/manual-grid.png)
189213

190214
## Roadmap
191-
- Tree flexibility. [tree.clj](src/excel_clj/tree.clj) should be able to work
192-
with any data shape given the same functions as [`clojure.core/tree-seq`](https://clojuredocs.org/clojure.core/tree-seq).
193-
Additionally, it should provide hooks for custom ways to aggregate columns
194-
(instead of expecting `Number` data and summing it) and whether or not to display
195-
sub-category level totals vs just grand totals.
196215

197216
- Templates! There's no reason to do all of the styling work programmatically.
198217
We should be able to download [some cool Google Sheets template](https://docs.google.com/spreadsheets/u/0/?usp=mkt_sheets_tpl)
@@ -225,7 +244,7 @@ that includes optional style data / cell merging instructions.
225244

226245
![Filled in template draft](resources/filled-template-draft.png)
227246

228-
- Reading & editing existing spradsheets. This should go hand in hand with
247+
- Reading & editing existing spreadsheets. This should go hand in hand with
229248
template generation.
230249

231250
- Formulas! We don't have them. I'm envisioning a syntax where a table column

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject org.clojars.mjdowney/excel-clj "1.0.0"
1+
(defproject org.clojars.mjdowney/excel-clj "1.1.0"
22
:description "Generate Excel documents & PDFs from Clojure data."
33
:url "https://github.com/matthewdowney/excel-clj"
44
:license {:name "Eclipse Public License"

resources/file-tree.png

144 KB
Loading

src/excel_clj/core.clj

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
[excel-clj.style :as style]
1515
[clojure.string :as string]
1616
[clojure.java.io :as io])
17-
(:import (org.apache.poi.ss.usermodel Cell RichTextString BorderStyle)
17+
(:import (org.apache.poi.ss.usermodel Cell RichTextString)
1818
(org.apache.poi.xssf.usermodel XSSFWorkbook XSSFSheet)
1919
(java.io FileOutputStream File)
2020
(java.awt Desktop HeadlessException)
@@ -200,18 +200,19 @@
200200
If provided, the formatters argument is a function that takes the integer
201201
depth of a category (increases with nesting) and returns a cell format for
202202
the row, and total-formatters is the same for rows that are totals."
203-
[t & {:keys [headers formatters total-formatters]
203+
[t & {:keys [headers formatters total-formatters data-format]
204204
:or {formatters style/default-tree-formatters
205-
total-formatters style/default-tree-total-formatters}}]
205+
total-formatters style/default-tree-total-formatters
206+
data-format :accounting}}]
206207
(try
207-
(let [tabular (apply tree/render-table (second t))
208+
(let [tabular (tree/accounting-table (second t))
208209
fmt-or-max (fn [fs n]
209210
(or (get fs n) (second (apply max-key first fs))))
210211
all-colls (or headers
211212
(sequence
212213
(comp
213214
(mapcat keys)
214-
(filter (complement #{:depth :label}))
215+
(filter (complement qualified-keyword?))
215216
(distinct))
216217
tabular))
217218
header-style {:font {:bold true} :alignment :right}]
@@ -225,14 +226,14 @@
225226

226227
;; Line items
227228
(for [line tabular]
228-
(let [total? (empty? (str (:label line)))
229+
(let [total? (::tree/total? line)
229230
format (or
230231
(fmt-or-max
231232
(if total? total-formatters formatters)
232-
(:depth line))
233+
(::tree/depth line))
233234
{})
234-
style (style/merge-all format {:data-format :accounting})]
235-
(into [{:value (:label line) :style (if total? {} style)}]
235+
style (style/merge-all format {:data-format data-format})]
236+
(into [{:value (::tree/label line) :style (if total? {} style)}]
236237
(map #(->{:value (get line %) :style style})) all-colls)))))
237238
(catch Exception e
238239
(throw (ex-info "Failed to render tree" {:tree t} e)))))

src/excel_clj/style.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175

176176
(def data-formats
177177
{:accounting "_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)"
178+
:number "#.###############"
178179
:ymd "yyyy-MM-dd"
179180
:percent "0.00%"})
180181

0 commit comments

Comments
 (0)