Skip to content

Commit

Permalink
Add xlsx.Read() for reading a stream
Browse files Browse the repository at this point in the history
  • Loading branch information
richardwilkes committed Feb 22, 2019
1 parent dbaaff6 commit ec44ff1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions formats/xlsx/sheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"archive/zip"
"encoding/xml"
"fmt"
"io"
"math"
"sort"
"strconv"
Expand All @@ -29,10 +30,24 @@ func Load(path string) ([]Sheet, error) {
return nil, errs.Wrap(err)
}
defer xio.CloseIgnoringErrors(r)
return load(&r.Reader)
}

// Read sheets from an .xlsx stream.
func Read(in io.ReaderAt, size int64) ([]Sheet, error) {
r, err := zip.NewReader(in, size)
if err != nil {
return nil, errs.Wrap(err)
}
return load(r)
}

func load(r *zip.Reader) ([]Sheet, error) {
var sheets []Sheet //nolint:prealloc
var sheetNames []string
var strs []string
var files []*zip.File
var err error
for _, f := range r.File {
switch {
case f.Name == "docProps/app.xml":
Expand Down

0 comments on commit ec44ff1

Please sign in to comment.