func main() { var mySlice [][][]string var value string path := "/home/jason/go/src/fortest/testfile.xlsx" mySlice, _ = xlsx.FileToSlice(path) // value = mySlice[0][0][0] // fmt.Println(value, "\n there is some testings: \n") row1 := mySlice[0][0] row2 := mySlice[0][1] row3 := mySlice[0][2] fmt.Println("sheet: ", len(mySlice), "rows: ", len(mySlice[0])) for _, row := range mySlice[0] { fmt.Println("colNum-of-this-row: ", len(row)) } fmt.Println("length:\t", len(row1), len(row2), len(row3), len(mySlice)) fmt.Println("row1:\n") for _, val := range row1 { fmt.Print(val, "\t") } fmt.Print("\n") fmt.Println("row2:\n") for _, val := range row2 { fmt.Print(val, "\t") } fmt.Print("\n") fmt.Println("row3:\n") for _, val := range row3 { fmt.Print(val, "\t") } fmt.Print("\n") }
// the XLSX's file convert to slice's type func (imxlsx *Importxlsx) FileToSlice() ([][]string, error) { sheet_myslice, err := xlsx.FileToSlice(imxlsx.ExecelxFile) if err != nil { return nil, err } return sheet_myslice[imxlsx.Sheet_num], err }
func readBaiduMap(baiduFile string) map[string]string { result, err := xlsx.FileToSlice(baiduFile) if err != nil { fmt.Println(err.Error()) return nil } retMap := make(map[string]string) //baidu map sheet // cols[0] fakename // cols[1] id sheet := result[0] for _, one_row := range sheet[1:] { retMap[one_row[2]] = one_row[1] } return retMap }
// OpenFile returns a new Reader that reads from path using dialect. func OpenFile(path string, dialect *FileDialect) (reader *Reader, err error) { if path == "" { return NewReader(os.Stdin, dialect) } md5hex, err := calcMd5Sum(path) if err != nil { return nil, err } extension := filepath.Ext(path) if extension == ".xlsx" { slices, err := xlsx.FileToSlice(path) if err != nil { return nil, err } var feeds [][]string if dialect.SheetNumber == 0 { feeds = slices[0] } else { if dialect.SheetNumber > len(slices) { return nil, fmt.Errorf("%s has only %d sheets, given sheet number is %d", path, len(slices), dialect.SheetNumber) } feeds = slices[dialect.SheetNumber-1] } reader = &Reader{ columns: make(map[int]int), slices: feeds, } } else { fp, err := os.Open(path) // TODO: Check `fp` is file or directory. // http://www.reddit.com/r/golang/comments/2fjwyk/isdir_in_go/ if err != nil { return nil, err } reader, err = NewReader(fp, dialect) reader.fp = fp } reader.path = path reader.logger = log.WithFields(log.Fields{"path": path}) reader.md5hex = md5hex return }
func readFeeCode(feeCodePath string) (cuFee, ctFee, cmFee, mmFee, bdFee map[string]string) { value, err := xlsx.FileToSlice(feeCodePath) if err != nil { return } oneSheet := value[0] cuFee = make(map[string]string) ctFee = make(map[string]string) cmFee = make(map[string]string) mmFee = make(map[string]string) bdFee = make(map[string]string) for _, oneRow := range oneSheet[1:] { name := oneRow[1] mm := oneRow[2] ct := oneRow[3] cu := oneRow[4] cm := oneRow[5] bd := oneRow[6] price := oneRow[7] if mm != "" { mmFee[mm] = mm + name + price } if cu != "" { cu = cu[len(cu)-3:] cuFee[cu] = cu + name + price } if ct != "" { ctFee[ct] = ct + name + price } if cm != "" { cm = cm[len(cm)-3:] cmFee[cm] = cm + name + price } if bd != "" { bdFee[bd] = bd + name + price } } fmt.Printf("feecode:ct %d,cu %d,cm %d,mm %d\n", len(ctFee), len(cuFee), len(cmFee), len(mmFee)) return }
package lua import ( "github.com/tealeg/xlsx" "github.com/telemetryapp/go-lua" "github.com/telemetryapp/goluago/util" ) var excelLibrary = []lua.RegistryFunction{ { "import", func(l *lua.State) int { path := lua.CheckString(l, 1) res, err := xlsx.FileToSlice(path) if err != nil { lua.Errorf(l, "%s", err) panic("unreachable") } util.DeepPush(l, res) return 1 }, }, } func openExcelLibrary(l *lua.State) { open := func(l *lua.State) int { lua.NewLibrary(l, excelLibrary)
func getDiaMap() *[]diaMap { var ( ds []diaMap d diaMap ) file, err := xlsx.FileToSlice("database/T_GRTB.xlsx") if err != nil { log.Println(err) } else if len(file) != 3 { log.Println("FILE ERROR, PAGE NUMBER ", len(file)) } for row := range file[0] { if row == 0 { continue } else if len(file[0][row]) < 5 { log.Println("File error") continue } ss := strings.Split(file[0][row][0], " ") d.protocol = "CAN" d.addr = file[0][row][0][:2] d.ecuName = file[0][row][1] d.group = file[0][row][2] d.series = file[0][row][3] d.discribe = file[0][row][4] if len(ss) < 3 { log.Println("FILE ERROR!") d.diag = file[0][row][0] continue } else if len(ss) == 4 { d.addr = ss[0] + "," + ss[1] ss[1], ss[2] = ss[2], ss[3] } if len(ss[1]) < 4 { log.Println("FILE ERROR!") d.diag = file[0][row][0] } else if ss[1][0] == '-' { d.diag = ss[2] } else if ss[1][0] == '0' { d.diag = ss[2] + fmt.Sprintf("%d%d", ss[1][2], ss[1][3]) } else if ss[1][0] == '.' { d.diag = ss[2] + fmt.Sprintf("%d%d", ss[1][1], ss[1][2]) } ds = append(ds, d) d = diaMap{} } for row := range file[1] { if row == 0 { continue } else if len(file[1][row]) < 5 { log.Println("File error") continue } ss := strings.Split(file[1][row][0], " ") d.protocol = "UDS" d.addr = ss[0] d.diag = ss[1] d.ecuName = file[1][row][1] d.group = file[1][row][2] d.series = file[1][row][3] d.discribe = file[1][row][4] ds = append(ds, d) d = diaMap{} } for row := range file[2] { if row == 0 { continue } else if len(file[2][row]) < 5 { log.Println("File error") continue } ss := strings.Split(file[2][row][0], " ") d.protocol = "Hybrid" d.addr = ss[0] d.diag = ss[1] d.ecuName = file[2][row][1] d.group = file[2][row][2] d.series = file[2][row][3] d.discribe = file[2][row][4] ds = append(ds, d) d = diaMap{} } return &ds }