-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
sheet_iterator.go
42 lines (34 loc) · 1.08 KB
/
sheet_iterator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) 2017 Andrey Gayvoronsky <[email protected]>
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package xlsx
//SheetIterator is a interface for iterating sheets inside of Spreadsheet
type SheetIterator interface {
//Next returns next Sheet in Spreadsheet and corresponding index
Next() (idx int, sheet Sheet)
//HasNext returns true if there are sheets to iterate or false in other case
HasNext() bool
}
//sheetIterator is object that holds required information for common sheet's iterator
type sheetIterator struct {
idx int
max int
xl *Spreadsheet
}
var _ SheetIterator = (*sheetIterator)(nil)
func newSheetIterator(xl *Spreadsheet) SheetIterator {
return &sheetIterator{
xl: xl,
idx: -1,
max: len(xl.sheets) - 1,
}
}
//Next returns next Sheet in Spreadsheet and corresponding index
func (i *sheetIterator) Next() (int, Sheet) {
i.idx++
return i.idx, i.xl.Sheet(i.idx)
}
//HasNext returns true if there are sheets to iterate or false in other case
func (i *sheetIterator) HasNext() bool {
return i.idx < i.max
}