go get github.com/tiptok/tabExample read table from excel(xlsx、xls)、html-table,and write to a file
package main
import (
"fmt""os""github.com/tiptok/tab"
)
funcmain() {
filename:="testdata/test.xlsx"file, err:=os.Open(filename)
iferr!=nil {
panic(err)
}
tabulator:=tab.NewTabulator(tab.WithReadFrom(tab.XLSX))
table, err:=tabulator.Open(file)
iferr!=nil {
panic(err)
}
fmt.Println(table)
err=tabulator.Write(tab.CSV, filename)
iferr!=nil {
panic(err)
}
}Set XLSX column widths:
writer:=tab.NewXLSXWriterTo(table.HeaderInfo.Columns, table.Rows).
SetColumnWidths(20, 40, 15)
err:=writer.Save("out.xlsx")
iferr!=nil {
panic(err)
}More example In example_test.go
- github.com/extrame/xls
- github.com/xuri/excelize/v2
- github.com/nfx/go-htmltable#page