summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2018-01-29 20:00:39 +0800
committerGitHub <noreply@github.com>2018-01-29 20:00:39 +0800
commit12760a7ee6d0256c44da0a16a0da1c8730517ee3 (patch)
tree1c0a9407ff102b678b415f5c0549d404bb08003a
parent6f4e4d9ef1be030a05f48aa5dda900f2dc9cb851 (diff)
parente556c25047a887d41c97ef9df7941ba585ba852b (diff)
Merge pull request #184 from martinal/speedup-setcellstyle-more
Speedup `SetCellStyle()` more.
-rw-r--r--styles.go25
1 files changed, 4 insertions, 21 deletions
diff --git a/styles.go b/styles.go
index 8cee5ff..7321c18 100644
--- a/styles.go
+++ b/styles.go
@@ -2307,6 +2307,7 @@ func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) {
vyAxis := vrow - 1
vxAxis := TitleToNumber(vcol)
+ // Correct the coordinate area, such correct C1:B3 to B1:C3.
if vxAxis < hxAxis {
hcell, vcell = vcell, hcell
vxAxis, hxAxis = hxAxis, vxAxis
@@ -2317,32 +2318,14 @@ func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) {
vyAxis, hyAxis = hyAxis, vyAxis
}
- // Correct the coordinate area, such correct C1:B3 to B1:C3.
- hcell = ToAlphaString(hxAxis) + strconv.Itoa(hyAxis+1)
- vcell = ToAlphaString(vxAxis) + strconv.Itoa(vyAxis+1)
-
xlsx := f.workSheetReader(sheet)
completeRow(xlsx, vyAxis+1, vxAxis+1)
completeCol(xlsx, vyAxis+1, vxAxis+1)
- for r, row := range xlsx.SheetData.Row {
- if r < hyAxis {
- continue
- } else if r > vyAxis {
- break
- }
-
- for k, c := range row.C {
- if k < hxAxis {
- continue
- } else if k > vxAxis {
- break
- }
-
- if checkCellInArea(c.R, hcell+":"+vcell) {
- xlsx.SheetData.Row[r].C[k].S = styleID
- }
+ for r := hyAxis; r <= vyAxis; r++ {
+ for k := hxAxis; k <= vxAxis; k++ {
+ xlsx.SheetData.Row[r].C[k].S = styleID
}
}
}