Skip to content

Commit 1e7f006

Browse files
Merge pull request #13 from keanedp/update_dependencies_and_migrate_jodconverter
Update dependencies and resolve JODConverter breaking changes
2 parents 0ca1288 + c54251f commit 1e7f006

File tree

6 files changed

+95
-47
lines changed

6 files changed

+95
-47
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Lein:
2323
- [Grids](#grids)
2424
- [Templates](#templates)
2525
- [Roadmap](#roadmap)
26+
- [Development](#development)
27+
- [Unit Tests](#unit-tests)
28+
- [Office Integration Tests](#office-integration-tests)
29+
- [All Tests](#all-tests)
2630

2731
## Getting Started
2832

@@ -113,7 +117,7 @@ contains final result of those calculations.
113117

114118
### PDF Generation
115119

116-
If you're on a system that uses an OpenOffice implementation of Excel, PDF
120+
If you're on a system that uses a LibreOffice or Apache OpenOffice implementation of Excel, PDF
117121
generation works the same was as creating a spreadsheet:
118122

119123
```clojure
@@ -251,3 +255,25 @@ For example, you can try:
251255
not sure what the best way to extract style data is, since there are so many
252256
possible values.
253257

258+
## Development
259+
260+
### Unit Tests
261+
262+
Standard unit tests can be run with the following command:
263+
264+
`$ lein test`
265+
266+
### Office Integration Tests
267+
268+
This test selector is designed to run tests that are dependent on the presence of LibreOffice or OpenOffice.
269+
270+
These tests can be run with:
271+
272+
`$ lein test :office-integrations`
273+
274+
### All Tests
275+
276+
Run all tests with the following command:
277+
278+
`$ lein test :all`
279+

project.clj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
:url "https://github.com/matthewdowney/excel-clj"
44
:license {:name "Eclipse Public License"
55
:url "http://www.eclipse.org/legal/epl-v10.html"}
6-
:dependencies [[org.clojure/clojure "1.10.1"]
7-
[com.taoensso/encore "3.12.1"]
6+
:dependencies [[org.clojure/clojure "1.10.3"]
7+
[com.taoensso/encore "3.21.0"]
88
[com.taoensso/tufte "2.2.0"]
9-
[org.apache.poi/poi-ooxml "4.1.2"]
10-
[org.jodconverter/jodconverter-core "4.0.0-RELEASE"]])
9+
[org.apache.poi/poi-ooxml "5.2.0"]
10+
[org.jodconverter/jodconverter-local "4.4.2"]]
11+
:profiles {:test {:dependencies [[org.apache.logging.log4j/log4j-core "2.17.1"]
12+
[org.slf4j/slf4j-nop "1.7.36"]]}}
13+
:test-selectors {:default (complement :office-integrations)
14+
:office-integrations :office-integrations})

src/excel_clj/file.clj

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
(:import (org.apache.poi.xssf.streaming SXSSFSheet)
1616
(org.apache.poi.ss.usermodel Sheet)
1717
(java.io File)
18-
(org.jodconverter.office DefaultOfficeManagerBuilder)
19-
(org.jodconverter OfficeDocumentConverter)
18+
(org.jodconverter.local.office LocalOfficeManager)
19+
(org.jodconverter.local LocalConverter)
2020
(java.awt Desktop HeadlessException)))
2121

2222

@@ -140,16 +140,20 @@
140140
"Convert the `from-document`, either a File or a path to any office document,
141141
to pdf format and write the pdf to the given pdf-path.
142142
143-
Requires OpenOffice. See https://github.com/sbraconnier/jodconverter.
143+
Requires LibreOffice or Apache OpenOffice https://github.com/sbraconnier/jodconverter
144144
145145
Returns a File pointing at the PDF."
146146
[from-document pdf-path]
147147
(let [path (force-extension pdf-path "pdf")
148-
office-manager (.build (DefaultOfficeManagerBuilder.))]
148+
office-manager (-> (LocalOfficeManager/builder)
149+
(.build))]
149150
(.start office-manager)
150151
(try
151-
(let [document-converter (OfficeDocumentConverter. office-manager)]
152-
(.convert document-converter (io/file from-document) (io/file path)))
152+
(let [document-converter (LocalConverter/make office-manager)]
153+
(-> document-converter
154+
(.convert (io/file from-document))
155+
(.to (io/file path))
156+
(.execute)))
153157
(finally
154158
(.stop office-manager)))
155159
(io/file path)))
@@ -181,37 +185,38 @@
181185
(open (write-pdf! workbook (temp ".pdf"))))
182186

183187

184-
(defn example
185-
"Write & open a sheet composed of a simple grid."
186-
[]
187-
(let [grid [["A" "B" "C"]
188-
[1 2 3]]]
189-
(quick-open! {"Sheet 1" grid})))
190-
191-
192-
(defn example-plus
193-
"Write & open a sheet composed of a more involved grid."
194-
[]
195-
(let [t (java.util.Calendar/getInstance)
196-
grid [["String" "Abc"]
197-
["Numbers" 100M 1.234 1234 12345N]
198-
["Date (not styled, styled)" t (style t {:data-format :ymd})]]
199-
200-
header-style {:border-bottom :thin :font {:bold true}}
201-
header-rows [[(-> "Type"
202-
(style header-style)
203-
(dims {:height 2})
204-
(style {:vertical-alignment :center}))
205-
(-> "Examples"
206-
(style header-style)
207-
(dims {:width 4})
208-
(style {:alignment :center :border-bottom :none}))]
209-
(mapv #(style % {:font {:italic true}
210-
:alignment :center
211-
:border-bottom :thin})
212-
[nil 1 2 3 4])]
213-
excel-file (quick-open! {"Sheet 1" (concat header-rows grid)})]
214-
(try
215-
(open (convert-pdf! excel-file (temp ".pdf")))
216-
(catch Exception e
217-
(println "(Couldn't open a PDF on this platform.)")))))
188+
(comment
189+
(defn example
190+
"Write & open a sheet composed of a simple grid."
191+
[]
192+
(let [grid [["A" "B" "C"]
193+
[1 2 3]]]
194+
(quick-open! {"Sheet 1" grid})))
195+
196+
197+
(defn example-plus
198+
"Write & open a sheet composed of a more involved grid."
199+
[]
200+
(let [t (java.util.Calendar/getInstance)
201+
grid [["String" "Abc"]
202+
["Numbers" 100M 1.234 1234 12345N]
203+
["Date (not styled, styled)" t (style t {:data-format :ymd})]]
204+
205+
header-style {:border-bottom :thin :font {:bold true}}
206+
header-rows [[(-> "Type"
207+
(style header-style)
208+
(dims {:height 2})
209+
(style {:vertical-alignment :center}))
210+
(-> "Examples"
211+
(style header-style)
212+
(dims {:width 4})
213+
(style {:alignment :center :border-bottom :none}))]
214+
(mapv #(style % {:font {:italic true}
215+
:alignment :center
216+
:border-bottom :thin})
217+
[nil 1 2 3 4])]
218+
excel-file (quick-open! {"Sheet 1" (concat header-rows grid)})]
219+
(try
220+
(open (convert-pdf! excel-file (temp ".pdf")))
221+
(catch Exception e
222+
(println "(Couldn't open a PDF on this platform.)"))))))

test/excel_clj/core_test.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@
5454
(println "Writing example template...")
5555
(let [template (clojure.java.io/resource "uptime-template.xlsx")
5656
new-data {"raw" (table-grid example-template-data)}]
57-
(append! new-data template "filled-in-template.xlsx")))
57+
(append! new-data template temp-file)))
5858
(finally
5959
(io/delete-file temp-file)))))

test/excel_clj/file_test.clj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(ns excel-clj.file-test
2+
(:require [clojure.test :refer :all]
3+
[excel-clj.file :as file]
4+
[clojure.java.io :as io]))
5+
6+
(deftest ^:office-integrations convert-to-pdf-test
7+
(let [input-file (clojure.java.io/resource "uptime-template.xlsx")
8+
temp-pdf-file (io/file (file/temp ".pdf"))]
9+
(try
10+
(testing "Convert XLSX file to PDF"
11+
(println "Writing example PDF...")
12+
(file/convert-pdf! input-file temp-pdf-file))
13+
(finally
14+
(io/delete-file temp-pdf-file)))))

test/excel_clj/poi_test.clj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
:success)
1212
"Example function writes successfully."))
1313

14-
1514
(deftest performance-test
1615
(testing "Performance is reasonable"
1716
(println "Starting performance test -- writing to a temp file...")

0 commit comments

Comments
 (0)