forked from p30928647/excelize
This commit is contained in:
parent
0dd616b18f
commit
82bb1153d7
12
lib.go
12
lib.go
|
@ -24,10 +24,13 @@ import (
|
||||||
// ReadZipReader can be used to read the spreadsheet in memory without touching the
|
// ReadZipReader can be used to read the spreadsheet in memory without touching the
|
||||||
// filesystem.
|
// filesystem.
|
||||||
func ReadZipReader(r *zip.Reader) (map[string][]byte, int, error) {
|
func ReadZipReader(r *zip.Reader) (map[string][]byte, int, error) {
|
||||||
|
var err error
|
||||||
fileList := make(map[string][]byte, len(r.File))
|
fileList := make(map[string][]byte, len(r.File))
|
||||||
worksheets := 0
|
worksheets := 0
|
||||||
for _, v := range r.File {
|
for _, v := range r.File {
|
||||||
fileList[v.Name] = readFile(v)
|
if fileList[v.Name], err = readFile(v); err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
if strings.HasPrefix(v.Name, "xl/worksheets/sheet") {
|
if strings.HasPrefix(v.Name, "xl/worksheets/sheet") {
|
||||||
worksheets++
|
worksheets++
|
||||||
}
|
}
|
||||||
|
@ -53,16 +56,17 @@ func (f *File) saveFileList(name string, content []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read file content as string in a archive file.
|
// Read file content as string in a archive file.
|
||||||
func readFile(file *zip.File) []byte {
|
func readFile(file *zip.File) ([]byte, error) {
|
||||||
rc, err := file.Open()
|
rc, err := file.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Println(err)
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
dat := make([]byte, 0, file.FileInfo().Size())
|
dat := make([]byte, 0, file.FileInfo().Size())
|
||||||
buff := bytes.NewBuffer(dat)
|
buff := bytes.NewBuffer(dat)
|
||||||
_, _ = io.Copy(buff, rc)
|
_, _ = io.Copy(buff, rc)
|
||||||
rc.Close()
|
rc.Close()
|
||||||
return buff.Bytes()
|
return buff.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SplitCellName splits cell name to column name and row number.
|
// SplitCellName splits cell name to column name and row number.
|
||||||
|
|
Loading…
Reference in New Issue