This is a creation in Article, where the information may have evolved or changed.
Golang Write XLS read class library, can realize the reading function of XLS table
func (w *workbook) Readallcells () (res [][]string) {for _, Sheet: = Range W.sheet s {w.preparesheet (sheet) if sheet. MaxRow! = 0 {Temp: = make ([][]string, Sheet. maxrow+1) for k, row: = Range sheet. Rows {data: = make ([]string, 0) If Len (row. Cols) > 0 {for _, col: = Range row. Cols {if uint16 (len (data)) <= Col. Lastcol () {data = append (data, make ([]string, Col. Lastcol ()-uint16 (len (data)) +1) ...) } str: = Col. String (W) for I: = uint16 (0); I < Col. Lastcol ()-col. Firstcol (+1); i++ {Data[col. Firstcol () +i] = Str[i]}} temp[k] = data} } res = append (res, temp ...) }} return}
Read Example:
Package main import ( "FMT" "GITHUB.COM/TEALEG/XLSX") func main () { excelfilename: = "/home/tealeg/ Foo.xlsx " xlfile, err: = xlsx. OpenFile (excelfilename) if err! = Nil { ... } For _, Sheet: = range Xlfile.sheets { for _, Row: = Range sheet. Rows { for _, Cell: = Range row. Cells { FMT. Printf ("%s\n", cell. String ())}}}}
Write an example:
Package main import ( "FMT" "GITHUB.COM/TEALEG/XLSX") func main () { var file *xlsx. File var sheet *xlsx. Sheet var row *xlsx. Row var cell *xlsx. Cell var err error File = xlsx. NewFile () sheet = file. Addsheet ("Sheet1") row = sheet. AddRow () cell = row. Addcell () cell. Value = "I am a cell!" Err = file. Save ("myxlsxfile.xlsx") if err! = Nil { FMT. Printf (Err. Error ()) }}