1
0
mirror of https://github.com/pbnjay/grate.git synced 2024-12-04 03:38:49 +02:00
A Go native tabular data extraction package. Currently supports .xls, .xlsx, .csv, .tsv formats.
Go to file
2023-10-05 22:24:35 -04:00
.github/workflows update xlsx tests to match xls 2022-02-23 01:05:14 -05:00
cmd grater: Print types with -v 2021-02-25 16:07:08 -05:00
commonxl fix XLS merged cells and ensure sentinals are correctly saved 2022-02-25 01:02:28 -05:00
simple provide access to format strings 2021-02-23 23:29:20 -05:00
testdata fixing and improving tests. allow fuzzier comparisons to cell content 2022-02-23 00:54:59 -05:00
xls fix formula parse error 2023-10-05 22:24:35 -04:00
xlsx deal with malformed "absolute" paths in relationship Targets 2022-08-09 19:17:34 -04:00
.gitignore misc cleanups 2021-02-14 14:16:46 -05:00
errs.go more consistent error handling 2021-02-12 10:44:23 -05:00
go.mod of course when I backport they release 1.16... 2021-02-17 02:17:02 -05:00
grate.go provide access to format strings 2021-02-23 23:29:20 -05:00
LICENSE switch to a less restrictive license 2021-02-17 12:27:12 -05:00
README.md switch to a less restrictive license 2021-02-17 12:27:12 -05:00

grate

A Go native tabular data extraction package. Currently supports .xls, .xlsx, .csv, .tsv formats.

Why?

Grate focuses on speed and stability first, and makes no attempt to parse charts, figures, or other content types that may be present embedded within the input files. It tries to perform as few allocations as possible and errs on the side of caution.

There are certainly still some bugs and edge cases, but we have run it successfully on a set of 400k .xls and .xlsx files to catch many bugs and error conditions. Please file an issue with any feedback and additional problem files.

Usage

Grate provides a simple standard interface for all supported filetypes, allowing access to both named worksheets in spreadsheets and single tables in plaintext formats.

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

License

All source code is licensed under the MIT License.