From fbef2d4922996d34466d668eb379d1deee63e281 Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Wed, 30 Sep 2015 11:44:14 +0800 Subject: [PATCH] add some example --- doc.go | 4 ++++ example_test.go | 28 ++++++++++++++++++++++++++++ xls_test.go | 21 --------------------- 3 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 doc.go create mode 100644 example_test.go diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..96aef6b --- /dev/null +++ b/doc.go @@ -0,0 +1,4 @@ +//xls package use to parse the 97 -2004 microsoft xls file(".xls" suffix, NOT ".xlsx" suffix ) +// +//there are some example in godoc, please follow them. +package xls diff --git a/example_test.go b/example_test.go new file mode 100644 index 0000000..2117bb6 --- /dev/null +++ b/example_test.go @@ -0,0 +1,28 @@ +package xls + +import ( + "fmt" +) + +func ExampleOpen() { + if xlFile, err := Open("Table.xls", "utf-8"); err == nil { + fmt.Println(xlFile.Author) + } +} + +//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) + col1 := sheet1.Rows[0].Cols[0] + col2 := sheet1.Rows[0].Cols[0] + for i := 0; i <= (int(sheet1.MaxRow)); i++ { + row1 := sheet1.Rows[uint16(i)] + col1 = row1.Cols[0] + col2 = row1.Cols[1] + fmt.Print("\n", col1.String(xlFile), ",", col2.String(xlFile)) + } + } + } +} diff --git a/xls_test.go b/xls_test.go index 7391115..8746bae 100644 --- a/xls_test.go +++ b/xls_test.go @@ -44,24 +44,3 @@ func TestMaxRow(t *testing.T) { } } } - -//read the content of first two cols in each row -func ExampleReadXls(t *testing.T) { - xlFile, err := Open("Table.xls", "utf-8") - if err != nil { - fmt.Fprintf(os.Stderr, "Failure: %v\n", err) - t.Error(err) - } - - if sheet1 := xlFile.GetSheet(0); sheet1 != nil { - fmt.Print("Total Lines ", sheet1.MaxRow, sheet1.Name) - col1 := sheet1.Rows[0].Cols[0] - col2 := sheet1.Rows[0].Cols[0] - for i := 0; i <= (int(sheet1.MaxRow)); i++ { - row1 := sheet1.Rows[uint16(i)] - col1 = row1.Cols[0] - col2 = row1.Cols[1] - fmt.Print("\n", col1.String(xlFile), ",", col2.String(xlFile)) - } - } -}