From 317ef65381b179b863dcd6b1f5479cc576a8376c Mon Sep 17 00:00:00 2001 From: mbresson Date: Fri, 19 Jan 2018 17:32:54 +0800 Subject: make SetCellStyle quicker by skipping conversions in checkCellInArea, and skipping area checks when we are sure the cell can't be before or past the current row/col Signed-off-by: Matthieu Bresson --- cell.go | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) (limited to 'cell.go') 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) } -- cgit v1.2.1