Skip to content

Commit 9a2748c

Browse files
committed
Add Sheet manipulation example to README.
1 parent 8973232 commit 9a2748c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Lein:
2323
- [What are the options for styling?](#what-are-the-options-for-styling?)
2424
- [Grids](#grids)
2525
- [Templates](#templates)
26+
- [Accessing The `Sheet`](#accessing-the-sheet)
2627
- [Roadmap](#roadmap)
2728
- [Development](#development)
2829
- [Unit Tests](#unit-tests)
@@ -271,6 +272,41 @@ For example, you can try:
271272
(excel/append! new-data template "filled-in-template.xlsx"))
272273
```
273274

275+
### Accessing The `Sheet`
276+
277+
There is not a way to directly access the `Sheet` object using the API. Instead,
278+
following the function `excel-clj.file/write*` as an example, open an Excel file
279+
and create the `Sheet`.
280+
281+
```clojure
282+
(require '[clojure.java.io :as io])
283+
(require '[excel-clj.core :as excel])
284+
(require '[excel-clj.file :as file])
285+
(require '[excel-clj.poi :as poi])
286+
(import '[org.apache.poi.ss.usermodel Sheet])
287+
288+
(let [worksheet-data (excel/table-grid [{:name "Trip 1"
289+
:miles 34.5
290+
:max-speed 15.2}
291+
{:name "Trip 2"
292+
:miles 14.1
293+
:max-speed 35.2}
294+
{:name "Trip 3"
295+
:miles 18.9
296+
:max-speed 21.1}])
297+
xlsx-filename (file/temp ".xlsx")
298+
excel-file (io/file xlsx-filename)]
299+
(with-open [poi-writer (poi/writer excel-file)]
300+
(let [sheet-writer (poi/sheet-writer poi-writer "Sheet1")
301+
worksheet ^Sheet (:sheet sheet-writer)]
302+
(doto worksheet
303+
(.setColumnWidth 1 500)
304+
(.createFreezePane 0 1))
305+
(file/write-rows! sheet-writer worksheet-data)))
306+
;; optionally open the created file
307+
(file/open excel-file))
308+
```
309+
274310
## Roadmap
275311

276312
- A way to read in a saved workbook to the `{sheet-name [[cell]]}` format. I'm

0 commit comments

Comments
 (0)