Skip to content

Commit fbef2d4

Browse files
committed
add some example
1 parent 56699cb commit fbef2d4

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

doc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//xls package use to parse the 97 -2004 microsoft xls file(".xls" suffix, NOT ".xlsx" suffix )
2+
//
3+
//there are some example in godoc, please follow them.
4+
package xls

example_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package xls
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func ExampleOpen() {
8+
if xlFile, err := Open("Table.xls", "utf-8"); err == nil {
9+
fmt.Println(xlFile.Author)
10+
}
11+
}
12+
13+
//Output: read the content of first two cols in each row
14+
func ExampleWorkBook_GetSheet() {
15+
if xlFile, err := Open("Table.xls", "utf-8"); err == nil {
16+
if sheet1 := xlFile.GetSheet(0); sheet1 != nil {
17+
fmt.Print("Total Lines ", sheet1.MaxRow, sheet1.Name)
18+
col1 := sheet1.Rows[0].Cols[0]
19+
col2 := sheet1.Rows[0].Cols[0]
20+
for i := 0; i <= (int(sheet1.MaxRow)); i++ {
21+
row1 := sheet1.Rows[uint16(i)]
22+
col1 = row1.Cols[0]
23+
col2 = row1.Cols[1]
24+
fmt.Print("\n", col1.String(xlFile), ",", col2.String(xlFile))
25+
}
26+
}
27+
}
28+
}

xls_test.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,3 @@ func TestMaxRow(t *testing.T) {
4444
}
4545
}
4646
}
47-
48-
//read the content of first two cols in each row
49-
func ExampleReadXls(t *testing.T) {
50-
xlFile, err := Open("Table.xls", "utf-8")
51-
if err != nil {
52-
fmt.Fprintf(os.Stderr, "Failure: %v\n", err)
53-
t.Error(err)
54-
}
55-
56-
if sheet1 := xlFile.GetSheet(0); sheet1 != nil {
57-
fmt.Print("Total Lines ", sheet1.MaxRow, sheet1.Name)
58-
col1 := sheet1.Rows[0].Cols[0]
59-
col2 := sheet1.Rows[0].Cols[0]
60-
for i := 0; i <= (int(sheet1.MaxRow)); i++ {
61-
row1 := sheet1.Rows[uint16(i)]
62-
col1 = row1.Cols[0]
63-
col2 = row1.Cols[1]
64-
fmt.Print("\n", col1.String(xlFile), ",", col2.String(xlFile))
65-
}
66-
}
67-
}

0 commit comments

Comments
 (0)