Skip to content

Commit df50c8f

Browse files
committed
Possibility of passing sheet idx
1 parent d608d0a commit df50c8f

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/bb_excel/core.clj

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,28 @@
186186

187187
(defn get-sheet
188188
"Get sheet from file"
189-
([filename sheetname]
190-
(get-sheet filename sheetname {}))
191-
([filename sheetname options]
189+
([filename]
190+
(get-sheet filename 1 {}))
191+
([filename sheetname-or-idx]
192+
(get-sheet filename sheetname-or-idx {}))
193+
([filename sheetname-or-idx options]
192194
(let [opts (merge defaults options)
193195
row (:row opts)
194196
hdr (:hdr opts)
195197
row (if (and hdr (zero? row)) 1 row)
196198
rows (:rows opts)
197199
fxn (:fxn opts)
198200
cols (map fxn (:columns opts))
199-
sheetid (:idx (first (filter #(= sheetname (:name %)) (get-sheet-names filename))))
201+
sheetid (cond
202+
(string? sheetname-or-idx)
203+
(:idx (first (filter #(= sheetname-or-idx (:name %)) (get-sheet-names filename))))
204+
205+
(and (integer? sheetname-or-idx) (pos? sheetname-or-idx))
206+
sheetname-or-idx
207+
208+
:else
209+
(let [message (format "Attr 'sheetname-or-idx' can only be string or positive number, but passed '%s'" sheetname-or-idx)]
210+
(throw (ex-info message {}))))
200211
zf (ZipFile. ^String filename)
201212
wb (.getEntry zf (str "xl/worksheets/sheet" sheetid ".xml"))
202213
ins (.getInputStream zf wb)

0 commit comments

Comments
 (0)