summaryrefslogtreecommitdiff
path: root/cell.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2018-01-19 20:58:26 +0800
committerGitHub <noreply@github.com>2018-01-19 20:58:26 +0800
commit541d29f3b2bfc62c05813a8d8725fca0a628bc81 (patch)
tree0942444e882e0f6db2aee1092150bcdb75448b85 /cell.go
parent50cdaed5a36f7112c2ff01504c475457f0d4944e (diff)
parent317ef65381b179b863dcd6b1f5479cc576a8376c (diff)
Merge pull request #180 from mbresson/optimize-SetCellStyle
make SetCellStyle quicker by skipping conversions in checkCellInArea,…
Diffstat (limited to 'cell.go')
-rw-r--r--cell.go25
1 files changed, 7 insertions, 18 deletions
diff --git a/cell.go b/cell.go
index 5d26338..bb363aa 100644
--- a/cell.go
+++ b/cell.go
@@ -455,27 +455,16 @@ func (f *File) SetCellDefault(sheet, axis, value string) {
// checkCellInArea provides function to determine if a given coordinate is
// within an area.
func checkCellInArea(cell, area string) bool {
- result := false
cell = strings.ToUpper(cell)
- col := string(strings.Map(letterOnlyMapF, cell))
- row, _ := strconv.Atoi(strings.Map(intOnlyMapF, cell))
- xAxis := row - 1
- yAxis := TitleToNumber(col)
+ area = strings.ToUpper(area)
ref := strings.Split(area, ":")
- hCol := string(strings.Map(letterOnlyMapF, ref[0]))
- hRow, _ := strconv.Atoi(strings.Map(intOnlyMapF, ref[0]))
- hyAxis := hRow - 1
- hxAxis := TitleToNumber(hCol)
+ from := ref[0]
+ to := ref[1]
- vCol := string(strings.Map(letterOnlyMapF, ref[1]))
- vRow, _ := strconv.Atoi(strings.Map(intOnlyMapF, ref[1]))
- vyAxis := vRow - 1
- vxAxis := TitleToNumber(vCol)
-
- if hxAxis <= yAxis && yAxis <= vxAxis && hyAxis <= xAxis && xAxis <= vyAxis {
- result = true
- }
+ col, row := getCellColRow(cell)
+ fromCol, fromRow := getCellColRow(from)
+ toCol, toRow := getCellColRow(to)
- return result
+ return axisLowerOrEqualThan(fromCol, col) && axisLowerOrEqualThan(col, toCol) && axisLowerOrEqualThan(fromRow, row) && axisLowerOrEqualThan(row, toRow)
}