golang excel 读取操作

excel读取的几个步骤
- xlsx.OpenFile(filename)
- for idx, sheet := range xlsFile.Sheets
- for idxrow, row := range sheet.Rows
- for idxcell, cell := range row.Cells

package main

import (
    "fmt"
    "github.com/tealeg/xlsx"
)

func main() {
    excelFileName := "1.xlsx"
    xlFile, err := xlsx.OpenFile(excelFileName)
    if err != nil {
        panic(err)
    }
    for s, sheet := range xlFile.Sheets {
        if s == 1 {
            break
        }
        for _, row := range sheet.Rows {
            for j, cell := range row.Cells {
                if j == 0 {
                    fmt.Printf("\n")
                }
                switch cell.Type() {
                    case xlsx.CellTypeString:
                        fmt.Printf("str %d %s\t", j, cell.String())
                        break
                    case xlsx.CellTypeStringFormula:
                        fmt.Printf("formula %d %s\t", j, cell.Formula())
                        break
                    case xlsx.CellTypeNumeric:
                        x, _:= cell.Int64()
                        fmt.Printf("int %d %d\t", j, x)
                        break
                    case xlsx.CellTypeBool:
                        fmt.Printf("bool %d %v\t", j, cell.Bool())
                        break
                    case xlsx.CellTypeDate:
                        t, _ := cell.GetTime(false)
                        fmt.Printf("date %d %v\t", j, t)
                        break
                }
            }
        }
    }
}