golang excel 읽기 작업

2949 단어 golang

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("
"
) } 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 } } } } }

좋은 웹페이지 즐겨찾기