From 9b5b74d4801f60daa580fd282ff9fa058bb03385 Mon Sep 17 00:00:00 2001 From: Ri Xu Date: Mon, 16 Oct 2017 10:42:43 +0800 Subject: Performance optimization, use the array index instead of the value in range. --- cell.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'cell.go') diff --git a/cell.go b/cell.go index c47b1f1..36b8ef9 100644 --- a/cell.go +++ b/cell.go @@ -91,11 +91,11 @@ func (f *File) GetCellValue(sheet, axis string) string { if rows < xAxis { return "" } - for _, v := range xlsx.SheetData.Row { - if v.R == row { - for _, r := range v.C { - if axis == r.R { - val, _ := r.getValueFrom(f, f.sharedStringsReader()) + for k := range xlsx.SheetData.Row { + if xlsx.SheetData.Row[k].R == row { + for i := range xlsx.SheetData.Row[k].C { + if axis == xlsx.SheetData.Row[k].C[i].R { + val, _ := xlsx.SheetData.Row[k].C[i].getValueFrom(f, f.sharedStringsReader()) return val } } @@ -161,12 +161,12 @@ func (f *File) GetCellFormula(sheet, axis string) string { if rows < xAxis { return "" } - for _, v := range xlsx.SheetData.Row { - if v.R == row { - for _, f := range v.C { - if axis == f.R { - if f.F != nil { - return f.F.Content + for k := range xlsx.SheetData.Row { + if xlsx.SheetData.Row[k].R == row { + for i := range xlsx.SheetData.Row[k].C { + if axis == xlsx.SheetData.Row[k].C[i].R { + if xlsx.SheetData.Row[k].C[i].F != nil { + return xlsx.SheetData.Row[k].C[i].F.Content } } } @@ -256,12 +256,12 @@ func (f *File) GetCellHyperLink(sheet, axis string) (bool, string) { if xlsx.Hyperlinks == nil || axis == "" { return link, target } - for _, h := range xlsx.Hyperlinks.Hyperlink { - if h.Ref == axis { + for h := range xlsx.Hyperlinks.Hyperlink { + if xlsx.Hyperlinks.Hyperlink[h].Ref == axis { link = true - target = h.Location - if h.RID != "" { - target = f.getSheetRelationshipsTargetByID(sheet, h.RID) + target = xlsx.Hyperlinks.Hyperlink[h].Location + if xlsx.Hyperlinks.Hyperlink[h].RID != "" { + target = f.getSheetRelationshipsTargetByID(sheet, xlsx.Hyperlinks.Hyperlink[h].RID) } } } -- cgit v1.2.1