Save a dataset to an Excel file.
Options are:
:sheet defaults to "dataset" if not provided.
:use-bold defaults to true. Set the header line in bold.
Examples:
(use '(incanter core datasets excel))
(save-xls (get-dataset :cars) "/tmp/cars.xls")
(defn ^{:doc "Save a dataset to an Excel file.
Options are:
:sheet defaults to \"dataset\" if not provided.
:use-bold defaults to true. Set the header line in bold.
Examples:
(use '(incanter core datasets excel))
(save-xls (get-dataset :cars) \"/tmp/cars.xls\")
"}
save-xls
[^:incanter.core/dataset dataset ^String filename & options]
(write-file
(let [opts (when options (apply assoc {} options))
bold-header (or (:use-bold opts) true)
workbook-blob (let [w (HSSFWorkbook.)]
{:workbook w
:normal (make-font true w)
:bold (make-font false w)})
workbook-sheet (. (:workbook workbook-blob) createSheet (or (:sheet opts) "dataset"))
align-row (fn [row cols] (map #(get row %1) cols))]
(write-line workbook-sheet 0 (:column-names dataset) (if bold-header (:bold workbook-blob) (:normal workbook-blob)))
(do-loop
#(write-line workbook-sheet %1 (align-row %2 (:column-names dataset)) (:normal workbook-blob))
1
(:rows dataset))
(:workbook workbook-blob))
filename))
Comments top
No comments for save-xls. Log in to add a comment.