forked from plandem/xlsx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
col_iterator.go
43 lines (35 loc) · 1.05 KB
/
col_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
43
// 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
//ColIterator is a interface for iterating cols inside of sheet
type ColIterator interface {
//Next returns next Col in sheet and corresponding index
Next() (idx int, col *Col)
//HasNext returns true if there are cols to iterate or false in other case
HasNext() bool
}
//colIterator is object that holds required information for common col's iterator
type colIterator struct {
idx int
max int
sheet Sheet
}
var _ ColIterator = (*colIterator)(nil)
func newColIterator(sheet Sheet) ColIterator {
cols, _ := sheet.Dimension()
return &colIterator{
idx: -1,
max: cols - 1,
sheet: sheet,
}
}
//Next returns next Col in sheet and corresponding index
func (i *colIterator) Next() (int, *Col) {
i.idx++
return i.idx, i.sheet.Col(i.idx)
}
//HasNext returns true if there are cols to iterate or false in other case
func (i *colIterator) HasNext() bool {
return i.idx < i.max
}