summaryrefslogtreecommitdiff
path: root/excelize.go
diff options
context:
space:
mode:
authorRi Xu <xuri.me@gmail.com>2017-02-12 19:03:24 +0800
committerRi Xu <xuri.me@gmail.com>2017-02-12 19:03:24 +0800
commit0833a9d5dab846ed01be52fa59c97ede36ee4a93 (patch)
tree9daaf8583f716a924aeb108b7255808d811f3e8c /excelize.go
parent53564cbe57522467a7e0febd0c9ae4374fa90808 (diff)
- Improved performance when reading large files, call Token to read tokens one by one instead Unmarshal. Related issue #20 ;
- Fix go test typo; - Update README
Diffstat (limited to 'excelize.go')
-rw-r--r--excelize.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/excelize.go b/excelize.go
index ed36589..bc37c0a 100644
--- a/excelize.go
+++ b/excelize.go
@@ -10,6 +10,7 @@ import (
// File define a populated XLSX file struct.
type File struct {
+ checked map[string]bool
XLSX map[string]string
Path string
SheetCount int
@@ -21,6 +22,7 @@ func OpenFile(filename string) (*File, error) {
var f *zip.ReadCloser
var err error
file := make(map[string]string)
+ c := make(map[string]bool)
sheetCount := 0
f, err = zip.OpenReader(filename)
if err != nil {
@@ -28,6 +30,7 @@ func OpenFile(filename string) (*File, error) {
}
file, sheetCount, _ = ReadZip(f)
return &File{
+ checked: c,
XLSX: file,
Path: filename,
SheetCount: sheetCount,
@@ -66,6 +69,15 @@ func (f *File) SetCellInt(sheet string, axis string, value int) {
var xlsx xlsxWorksheet
name := "xl/worksheets/" + strings.ToLower(sheet) + ".xml"
xml.Unmarshal([]byte(f.readXML(name)), &xlsx)
+ if f.checked == nil {
+ f.checked = make(map[string]bool)
+ }
+ ok := f.checked[name]
+ if !ok {
+ xlsx = checkRow(xlsx)
+ f.checked[name] = true
+ }
+
if xlsx.MergeCells != nil {
for i := 0; i < len(xlsx.MergeCells.Cells); i++ {
if checkCellInArea(axis, xlsx.MergeCells.Cells[i].Ref) {
@@ -98,6 +110,14 @@ func (f *File) SetCellStr(sheet string, axis string, value string) {
var xlsx xlsxWorksheet
name := "xl/worksheets/" + strings.ToLower(sheet) + ".xml"
xml.Unmarshal([]byte(f.readXML(name)), &xlsx)
+ if f.checked == nil {
+ f.checked = make(map[string]bool)
+ }
+ ok := f.checked[name]
+ if !ok {
+ xlsx = checkRow(xlsx)
+ f.checked[name] = true
+ }
if xlsx.MergeCells != nil {
for i := 0; i < len(xlsx.MergeCells.Cells); i++ {
if checkCellInArea(axis, xlsx.MergeCells.Cells[i].Ref) {
@@ -133,6 +153,14 @@ func (f *File) SetCellDefault(sheet string, axis string, value string) {
var xlsx xlsxWorksheet
name := "xl/worksheets/" + strings.ToLower(sheet) + ".xml"
xml.Unmarshal([]byte(f.readXML(name)), &xlsx)
+ if f.checked == nil {
+ f.checked = make(map[string]bool)
+ }
+ ok := f.checked[name]
+ if !ok {
+ xlsx = checkRow(xlsx)
+ f.checked[name] = true
+ }
if xlsx.MergeCells != nil {
for i := 0; i < len(xlsx.MergeCells.Cells); i++ {
if checkCellInArea(axis, xlsx.MergeCells.Cells[i].Ref) {