Skip to content

Commit

Permalink
Possibility of passing sheet idx
Browse files Browse the repository at this point in the history
  • Loading branch information
velios committed Sep 16, 2023
1 parent d608d0a commit df50c8f
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/bb_excel/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,28 @@

(defn get-sheet
"Get sheet from file"
([filename sheetname]
(get-sheet filename sheetname {}))
([filename sheetname options]
([filename]
(get-sheet filename 1 {}))
([filename sheetname-or-idx]
(get-sheet filename sheetname-or-idx {}))
([filename sheetname-or-idx options]
(let [opts (merge defaults options)
row (:row opts)
hdr (:hdr opts)
row (if (and hdr (zero? row)) 1 row)
rows (:rows opts)
fxn (:fxn opts)
cols (map fxn (:columns opts))
sheetid (:idx (first (filter #(= sheetname (:name %)) (get-sheet-names filename))))
sheetid (cond
(string? sheetname-or-idx)
(:idx (first (filter #(= sheetname-or-idx (:name %)) (get-sheet-names filename))))

(and (integer? sheetname-or-idx) (pos? sheetname-or-idx))
sheetname-or-idx

:else
(let [message (format "Attr 'sheetname-or-idx' can only be string or positive number, but passed '%s'" sheetname-or-idx)]
(throw (ex-info message {}))))
zf (ZipFile. ^String filename)
wb (.getEntry zf (str "xl/worksheets/sheet" sheetid ".xml"))
ins (.getInputStream zf wb)
Expand Down

0 comments on commit df50c8f

Please sign in to comment.