Grate is a Go-native package for extracting tabular data from .xls, .xlsx, .csv, and .tsv files. It provides a unified interface for accessing data, whether it is a single table in a plaintext file or multiple worksheets in a spreadsheet.
To use grate, you must import the core package and the specific driver packages for the file formats you intend to support using blank imports (_).
Supported formats and their drivers:
.xls: github.com/pbnjay/grate/xls.xlsx: github.com/pbnjay/grate/xlsx.csv and .tsv: github.com/pbnjay/grate/simple
package main
import (
"fmt"
"os"
"strings"
"github.com/pbnjay/grate"
_ "github.com/pbnjay/grate/simple" // tsv and csv support
_ "github.com/pbnjay/grate/xls"
_ "github.com/pbnjay/grate/xlsx"
)
func main() {
wb, _ := grate.Open(os.Args[1]) // open the file
sheets, _ := wb.List() // list available sheets
for _, s := range sheets { // enumerate each sheet name
sheet, _ := wb.Get(s) // open the sheet
for sheet.Next() { // enumerate each row of data
row := sheet.Strings() // get the row's content as []string
fmt.Println(strings.Join(row, "\t"))
}
}
wb.Close()
}