docjure
docjure copied to clipboard
Suggestion - read the entire workbook contents, instead of just the selected cell-names
In order to provide a complete reader, I needed this function. Maybe you'll want to use it in docjure, or write a similar one (note that I made keywords, but that's not exactly required):
(defn process-workbook [#^Workbook wb]
"Returns a vector with maps for each sheet (a name and a vector with maps for each row, in the form [{:a1 valA1, :c2 valC2, ...}, ...]."
(vec
(for [sheet (sheet-seq wb)]
(hash-map :name (sheet-name sheet)
:rows (let [rows (vec
(for [row (into-seq sheet)]
(map read-cell row)))
headers (map keyword (first rows))
data (rest rows)]
(map #(zipmap headers %) data))))))
Nice code. I have another use case for something similar in one of the clients we wrote, so I will think about combining the two ideas.
Cheers, Martin