diff options
author | mbresson <matthieu.bresson@kapptivate.com> | 2018-01-19 17:32:54 +0800 |
---|---|---|
committer | mbresson <matthieu.bresson@kapptivate.com> | 2018-01-19 17:49:09 +0800 |
commit | 317ef65381b179b863dcd6b1f5479cc576a8376c (patch) | |
tree | 0942444e882e0f6db2aee1092150bcdb75448b85 /lib.go | |
parent | 50cdaed5a36f7112c2ff01504c475457f0d4944e (diff) |
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
Diffstat (limited to 'lib.go')
-rw-r--r-- | lib.go | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -7,6 +7,7 @@ import ( "io" "log" "math" + "unicode" ) // ReadZipReader can be used to read an XLSX in memory without touching the @@ -132,3 +133,43 @@ func defaultTrue(b *bool) bool { } return *b } + +// axisLowerOrEqualThan returns true if axis1 <= axis2 +// axis1/axis2 can be either a column or a row axis, e.g. "A", "AAE", "42", "1", etc. +// +// For instance, the following comparisons are all true: +// +// "A" <= "B" +// "A" <= "AA" +// "B" <= "AA" +// "BC" <= "ABCD" (in a XLSX sheet, the BC col comes before the ABCD col) +// "1" <= "2" +// "2" <= "11" (in a XLSX sheet, the row 2 comes before the row 11) +// and so on +func axisLowerOrEqualThan(axis1, axis2 string) bool { + if len(axis1) < len(axis2) { + return true + } else if len(axis1) > len(axis2) { + return false + } else { + return axis1 <= axis2 + } +} + +// getCellColRow returns the two parts of a cell identifier (its col and row) as strings +// +// For instance: +// +// "C220" => "C", "220" +// "aaef42" => "aaef", "42" +// "" => "", "" +func getCellColRow(cell string) (col, row string) { + for index, rune := range cell { + if unicode.IsDigit(rune) { + return cell[:index], cell[index:] + } + + } + + return cell, "" +} |