20
0
xls/example_test.go

38 lines
852 B
Go
Raw Normal View History

2015-09-30 05:44:14 +02:00
package xls
import (
"fmt"
)
func ExampleOpen() {
if xlFile, err := Open("Table.xls", "utf-8"); err == nil {
fmt.Println(xlFile.Author)
}
}
2016-01-22 07:50:15 +01:00
func ExampleWorkBook_NumberSheets() {
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)
}
}
}
2015-09-30 05:44:14 +02:00
//Output: read the content of first two cols in each row
func ExampleWorkBook_GetSheet() {
if xlFile, err := Open("Table.xls", "utf-8"); err == nil {
if sheet1 := xlFile.GetSheet(0); sheet1 != nil {
fmt.Print("Total Lines ", sheet1.MaxRow, sheet1.Name)
2017-02-21 09:27:01 +01:00
col1 := sheet1.Row(0).Col(0)
col2 := sheet1.Row(0).Col(0)
2015-09-30 05:44:14 +02:00
for i := 0; i <= (int(sheet1.MaxRow)); i++ {
2017-02-21 09:27:01 +01:00
row1 := sheet1.Row(i)
col1 = row1.Col(0)
col2 = row1.Col(1)
fmt.Print("\n", col1, ",", col2)
2015-09-30 05:44:14 +02:00
}
}
}
}