docjure icon indicating copy to clipboard operation
docjure copied to clipboard

Suggestion - read the entire workbook contents, instead of just the selected cell-names

Open edgargoncalves opened this issue 14 years ago • 1 comments

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))))))

edgargoncalves avatar Jul 24 '10 13:07 edgargoncalves

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

mjul avatar Jul 26 '10 16:07 mjul