From 35841caaf18b20af9e7b942ca8cbb7441f310382 Mon Sep 17 00:00:00 2001 From: Ri Xu Date: Mon, 26 Jun 2017 18:44:19 +0800 Subject: - Function `formattedValue()` performance improvement by avoid repeating deserialization, relate issue #64; - Make function `ToAlphaString()` exportable, relate issue #63 --- cell.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'cell.go') diff --git a/cell.go b/cell.go index 86c3567..0145b8e 100644 --- a/cell.go +++ b/cell.go @@ -70,8 +70,7 @@ func (f *File) formattedValue(s int, v string) string { if s == 0 { return v } - var styleSheet xlsxStyleSheet - xml.Unmarshal([]byte(f.readXML("xl/styles.xml")), &styleSheet) + styleSheet := f.stylesReader() ok := builtInNumFmtFunc[styleSheet.CellXfs.Xf[s].NumFmtID] if ok != nil { return ok(styleSheet.CellXfs.Xf[s].NumFmtID, v) @@ -200,7 +199,7 @@ func (f *File) MergeCell(sheet, hcell, vcell string) { if xlsx.MergeCells != nil { mergeCell := xlsxMergeCell{} // Correct the coordinate area, such correct C1:B3 to B1:C3. - mergeCell.Ref = toAlphaString(hxAxis+1) + strconv.Itoa(hyAxis+1) + ":" + toAlphaString(vxAxis+1) + strconv.Itoa(vyAxis+1) + mergeCell.Ref = ToAlphaString(hxAxis+1) + strconv.Itoa(hyAxis+1) + ":" + ToAlphaString(vxAxis+1) + strconv.Itoa(vyAxis+1) // Delete the merged cells of the overlapping area. for i := 0; i < len(xlsx.MergeCells.Cells); i++ { if checkCellInArea(hcell, xlsx.MergeCells.Cells[i].Ref) || checkCellInArea(strings.Split(xlsx.MergeCells.Cells[i].Ref, ":")[0], mergeCell.Ref) { @@ -213,7 +212,7 @@ func (f *File) MergeCell(sheet, hcell, vcell string) { } else { mergeCell := xlsxMergeCell{} // Correct the coordinate area, such correct C1:B3 to B1:C3. - mergeCell.Ref = toAlphaString(hxAxis+1) + strconv.Itoa(hyAxis+1) + ":" + toAlphaString(vxAxis+1) + strconv.Itoa(vyAxis+1) + mergeCell.Ref = ToAlphaString(hxAxis+1) + strconv.Itoa(hyAxis+1) + ":" + ToAlphaString(vxAxis+1) + strconv.Itoa(vyAxis+1) mergeCells := xlsxMergeCells{} mergeCells.Cells = append(mergeCells.Cells, &mergeCell) xlsx.MergeCells = &mergeCells -- cgit v1.2.1