|
125 | 125 | 1 {:font {:bold true}}
|
126 | 126 | 2 {:indention 2}
|
127 | 127 | 3 {:font {:italic true} :alignment :right})
|
128 |
| - |
129 |
| - get' (fn [m k] (or (get m k) (val (last m))))] |
| 128 | + num-format {:data-format :accounting} |
| 129 | + |
| 130 | + get' (fn [m k] (or (get m k) (val (last m)))) |
| 131 | + style-data (fn [row style-map] |
| 132 | + (let [label-key ""] |
| 133 | + (->> row |
| 134 | + (map (fn [[k v]] |
| 135 | + (if-not (= k label-key) |
| 136 | + [k (-> v |
| 137 | + (style num-format) |
| 138 | + (style style-map))] |
| 139 | + [k v]))) |
| 140 | + (into {}))))] |
130 | 141 | (tree/table
|
131 | 142 | ;; Insert total rows below nodes with children
|
132 | 143 | (fn render [parent node depth]
|
|
140 | 151 | (tree/table render node)
|
141 | 152 | ; total row
|
142 | 153 | (when (> (count node) 1)
|
143 |
| - [(style (assoc combined "" "") (get' total-fmts depth))]))) |
| 154 | + [(style-data (assoc combined "" "") (get' total-fmts depth))]))) |
144 | 155 | ; leaf
|
145 |
| - [(style (assoc node "" (name parent)) (get' fmts depth))])) |
| 156 | + [(style-data (assoc node "" (name parent)) (get' fmts (max depth 2)))])) |
146 | 157 | t)))
|
147 | 158 |
|
148 | 159 |
|
|
357 | 368 | (file/quick-open-pdf! workbook))
|
358 | 369 |
|
359 | 370 |
|
| 371 | +;; Some v1.X backwards compatibility |
| 372 | + |
| 373 | + |
| 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 | + |
| 378 | + |
| 379 | +(comment |
| 380 | + "Example: Using deprecated `tree` and `table` functions" |
| 381 | + (quick-open! |
| 382 | + {"tree" (tree |
| 383 | + ["Mock Balance Sheet for the year ending Dec 31st, 2018" |
| 384 | + ["Assets" |
| 385 | + [["Current Assets" |
| 386 | + [["Cash" {2018 100M, 2017 85M}] |
| 387 | + ["Accounts Receivable" {2018 5M, 2017 45M}]]] |
| 388 | + ["Investments" {2018 100M, 2017 10M}] |
| 389 | + ["Other" {2018 12M, 2017 8M}]]] |
| 390 | + ["Liabilities & Stockholders' Equity" |
| 391 | + [["Liabilities" |
| 392 | + [["Current Liabilities" |
| 393 | + [["Notes payable" {2018 5M, 2017 8M}] |
| 394 | + ["Accounts payable" {2018 10M, 2017 10M}]]] |
| 395 | + ["Long-term liabilities" {2018 100M, 2017 50M}]]] |
| 396 | + ["Equity" |
| 397 | + [["Common Stock" {2018 102M, 2017 80M}]]]]]]) |
| 398 | + "table" (table (for [n (range 100)] {"X" n "X^2" (* n n)}))})) |
| 399 | + |
| 400 | + |
360 | 401 | ;;; Performance tests for order-of-magnitude checks
|
361 | 402 |
|
362 | 403 |
|
|
445 | 486 |
|
446 | 487 |
|
447 | 488 | (defn example []
|
448 |
| - (file/quick-open! example-workbook-data)) |
| 489 | + (quick-open! example-workbook-data)) |
449 | 490 |
|
450 | 491 |
|
451 | 492 | (def example-template-data
|
|
471 | 512 | (let [template (clojure.java.io/resource "uptime-template.xlsx")
|
472 | 513 | new-data {"raw" (table-grid example-template-data)}]
|
473 | 514 | (file/open (append! new-data template "filled-in-template.xlsx"))))
|
474 |
| - |
475 |
| - |
476 |
| -;; Some v1.X backwards compatibility |
477 |
| - |
478 |
| - |
479 |
| -(def ^:deprecated tree (partial deprecated/tree table-grid with-title)) |
480 |
| -(def ^:deprecated table deprecated/table) |
481 |
| - |
482 |
| - |
483 |
| -(comment |
484 |
| - "Example: Using deprecated `tree` and `table` functions" |
485 |
| - (quick-open! |
486 |
| - {"tree" (tree |
487 |
| - ["Mock Balance Sheet for the year ending Dec 31st, 2018" |
488 |
| - ["Assets" |
489 |
| - [["Current Assets" |
490 |
| - [["Cash" {2018 100M, 2017 85M}] |
491 |
| - ["Accounts Receivable" {2018 5M, 2017 45M}]]] |
492 |
| - ["Investments" {2018 100M, 2017 10M}] |
493 |
| - ["Other" {2018 12M, 2017 8M}]]] |
494 |
| - ["Liabilities & Stockholders' Equity" |
495 |
| - [["Liabilities" |
496 |
| - [["Current Liabilities" |
497 |
| - [["Notes payable" {2018 5M, 2017 8M}] |
498 |
| - ["Accounts payable" {2018 10M, 2017 10M}]]] |
499 |
| - ["Long-term liabilities" {2018 100M, 2017 50M}]]] |
500 |
| - ["Equity" |
501 |
| - [["Common Stock" {2018 102M, 2017 80M}]]]]]]) |
502 |
| - "table" (table (for [n (range 100)] {"X" n "X^2" (* n n)}))})) |
|
0 commit comments