diff options
Diffstat (limited to 'lib.go')
-rw-r--r-- | lib.go | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -12,8 +12,8 @@ import ( // ReadZipReader can be used to read an XLSX in memory without touching the // filesystem. -func ReadZipReader(r *zip.Reader) (map[string]string, int, error) { - fileList := make(map[string]string) +func ReadZipReader(r *zip.Reader) (map[string][]byte, int, error) { + fileList := make(map[string][]byte) worksheets := 0 for _, v := range r.File { fileList[v.Name] = readFile(v) @@ -27,21 +27,24 @@ func ReadZipReader(r *zip.Reader) (map[string]string, int, error) { } // readXML provides function to read XML content as string. -func (f *File) readXML(name string) string { +func (f *File) readXML(name string) []byte { if content, ok := f.XLSX[name]; ok { return content } - return "" + return []byte{} } // saveFileList provides function to update given file content in file list of // XLSX. -func (f *File) saveFileList(name, content string) { - f.XLSX[name] = XMLHeader + content +func (f *File) saveFileList(name string, content []byte) { + newContent := make([]byte, 0, len(XMLHeader)+len(content)) + newContent = append(newContent, []byte(XMLHeader)...) + newContent = append(newContent, content...) + f.XLSX[name] = newContent } // Read file content as string in a archive file. -func readFile(file *zip.File) string { +func readFile(file *zip.File) []byte { rc, err := file.Open() if err != nil { log.Fatal(err) @@ -49,7 +52,7 @@ func readFile(file *zip.File) string { buff := bytes.NewBuffer(nil) io.Copy(buff, rc) rc.Close() - return string(buff.Bytes()) + return buff.Bytes() } // ToAlphaString provides function to convert integer to Excel sheet column |