Add NumSheets to get the number of sheets
This commit is contained in:
parent
1dd2ce626e
commit
1375b24d9d
@ -10,6 +10,15 @@ func ExampleOpen() {
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleNumberSheets() {
|
||||
if xlFile, err := Open("Table.xls", "utf-8"); err == nil {
|
||||
for i := 0; i < xlFile.NumSheets(); i++ {
|
||||
sheet := xlFile.GetSheet(i)
|
||||
fmt.Println(sheet.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Output: read the content of first two cols in each row
|
||||
func ExampleWorkBook_GetSheet() {
|
||||
if xlFile, err := Open("Table.xls", "utf-8"); err == nil {
|
||||
|
@ -210,16 +210,24 @@ func (w *WorkBook) prepareSheet(sheet *WorkSheet) {
|
||||
sheet.parse(w.rs)
|
||||
}
|
||||
|
||||
//Get one sheet by its number
|
||||
func (w *WorkBook) GetSheet(num int) *WorkSheet {
|
||||
if num < len(w.sheets) {
|
||||
s := w.sheets[num]
|
||||
if !s.parsed {
|
||||
w.prepareSheet(s)
|
||||
}
|
||||
return s
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//Get the number of all sheets, look into example
|
||||
func (w *WorkBook) NumSheets() int {
|
||||
return len(w.sheets)
|
||||
}
|
||||
|
||||
//helper function to read all cells from file
|
||||
func (w *WorkBook) ReadAllCells(max int) (res [][]string) {
|
||||
res = make([][]string, 0)
|
||||
|
@ -22,6 +22,7 @@ type WorkSheet struct {
|
||||
Rows map[uint16]*Row
|
||||
//NOTICE: this is the max row number of the sheet, so it should be count -1
|
||||
MaxRow uint16
|
||||
parsed bool
|
||||
}
|
||||
|
||||
func (w *WorkSheet) parse(buf io.ReadSeeker) {
|
||||
@ -39,6 +40,7 @@ func (w *WorkSheet) parse(buf io.ReadSeeker) {
|
||||
break
|
||||
}
|
||||
}
|
||||
w.parsed = true
|
||||
}
|
||||
|
||||
func (w *WorkSheet) parseBof(buf io.ReadSeeker, b *bof, pre *bof) *bof {
|
||||
|
Loading…
Reference in New Issue
Block a user