Skip to content

Commit

Permalink
Merge branch 'develop' for v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewdowney committed May 28, 2019
2 parents ea4d468 + 30d9d8e commit aad00d3
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 210 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log

## [1.1.0] - 2019-05-28
### Added
- More flexible tree rendering/aggregation

### Changed
- Replaced lots of redundant tree code with a `walk` function

## [1.0.0] - 2019-04-17
### Added
- PDF generation
Expand Down
33 changes: 26 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ common sense styling.

Lein:
```
[org.clojars.mjdowney/excel-clj "1.0.0"]
[org.clojars.mjdowney/excel-clj "1.1.0"]
```

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

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

Trees are pretty flexible — the only requirement that we impose is that their
leaves have the format `[string-label, map-of-numbers]`. We construct trees
using the same arguments we'd give to `clojure.core/tree-seq`, plus a walk
function.

We could make a tree for some part of our file system for example:

```clojure
(require '[excel-clj.tree :as tree] '[clojure.java.io :as io])
=> nil

(let [src-tree
(tree/walk
(fn [f xs]
(if-not (seq xs)
[(.getName f) {:size (.length f)}]
[(str (.getName f) "/") xs]))
#(.isDirectory %) #(.listFiles %) (io/file "."))]
(excel/quick-open
{"Source Tree" (excel/tree ["Source" [src-tree]] :data-format :number)}))
```

![An excel sheet is opened](resources/file-tree.png)


### PDF Generation

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

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

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

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

- Reading & editing existing spradsheets. This should go hand in hand with
- Reading & editing existing spreadsheets. This should go hand in hand with
template generation.

- Formulas! We don't have them. I'm envisioning a syntax where a table column
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject org.clojars.mjdowney/excel-clj "1.0.0"
(defproject org.clojars.mjdowney/excel-clj "1.1.0"
:description "Generate Excel documents & PDFs from Clojure data."
:url "https://github.com/matthewdowney/excel-clj"
:license {:name "Eclipse Public License"
Expand Down
Binary file added resources/file-tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 10 additions & 9 deletions src/excel_clj/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[excel-clj.style :as style]
[clojure.string :as string]
[clojure.java.io :as io])
(:import (org.apache.poi.ss.usermodel Cell RichTextString BorderStyle)
(:import (org.apache.poi.ss.usermodel Cell RichTextString)
(org.apache.poi.xssf.usermodel XSSFWorkbook XSSFSheet)
(java.io FileOutputStream File)
(java.awt Desktop HeadlessException)
Expand Down Expand Up @@ -200,18 +200,19 @@
If provided, the formatters argument is a function that takes the integer
depth of a category (increases with nesting) and returns a cell format for
the row, and total-formatters is the same for rows that are totals."
[t & {:keys [headers formatters total-formatters]
[t & {:keys [headers formatters total-formatters data-format]
:or {formatters style/default-tree-formatters
total-formatters style/default-tree-total-formatters}}]
total-formatters style/default-tree-total-formatters
data-format :accounting}}]
(try
(let [tabular (apply tree/render-table (second t))
(let [tabular (tree/accounting-table (second t))
fmt-or-max (fn [fs n]
(or (get fs n) (second (apply max-key first fs))))
all-colls (or headers
(sequence
(comp
(mapcat keys)
(filter (complement #{:depth :label}))
(filter (complement qualified-keyword?))
(distinct))
tabular))
header-style {:font {:bold true} :alignment :right}]
Expand All @@ -225,14 +226,14 @@

;; Line items
(for [line tabular]
(let [total? (empty? (str (:label line)))
(let [total? (::tree/total? line)
format (or
(fmt-or-max
(if total? total-formatters formatters)
(:depth line))
(::tree/depth line))
{})
style (style/merge-all format {:data-format :accounting})]
(into [{:value (:label line) :style (if total? {} style)}]
style (style/merge-all format {:data-format data-format})]
(into [{:value (::tree/label line) :style (if total? {} style)}]
(map #(->{:value (get line %) :style style})) all-colls)))))
(catch Exception e
(throw (ex-info "Failed to render tree" {:tree t} e)))))
Expand Down
1 change: 1 addition & 0 deletions src/excel_clj/style.clj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@

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

Expand Down
Loading

0 comments on commit aad00d3

Please sign in to comment.