From a9d3ee28693adfe920b3cd047f52862d8a79a00e Mon Sep 17 00:00:00 2001 From: Ri Xu Date: Tue, 30 Aug 2016 11:51:31 +0800 Subject: Init commit. --- lib.go | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 lib.go (limited to 'lib.go') diff --git a/lib.go b/lib.go new file mode 100644 index 0000000..e3d7a4f --- /dev/null +++ b/lib.go @@ -0,0 +1,132 @@ +package excelize + +import ( + "archive/zip" + "bytes" + "io" + "log" + "math" + "os" + "regexp" + "strconv" + "strings" +) + +// ReadZip() takes a pointer to a zip.ReadCloser and returns a +// xlsx.File struct populated with its contents. In most cases +// ReadZip is not used directly, but is called internally by OpenFile. +func ReadZip(f *zip.ReadCloser) ([]FileList, error) { + defer f.Close() + return ReadZipReader(&f.Reader) +} + +// ReadZipReader() can be used to read an XLSX in memory without +// touching the filesystem. +func ReadZipReader(r *zip.Reader) ([]FileList, error) { + var fileList []FileList + for _, v := range r.File { + singleFile := FileList{ + Key: v.Name, + Value: readFile(v), + } + fileList = append(fileList, singleFile) + } + return fileList, nil +} + +// Read XML content as string and replace drawing property in XML namespace of sheet +func readXml(files []FileList, name string) string { + for _, file := range files { + if file.Key == name { + return strings.Replace(file.Value, "