diff options
author | Ri Xu <xuri.me@gmail.com> | 2017-09-06 12:17:58 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-06 12:17:58 +0800 |
commit | cf1077dc9f85593d0d0da55a1c5e5728d1f2f181 (patch) | |
tree | 9307fb93ce9fb7ee54b8c44595da605976511f53 /lib.go | |
parent | 5354074fc278e3155a00cc94ec5eb5927e74be7a (diff) | |
parent | 1f93fc7bad0f1a4cd7f3b037a0f370561eae83b1 (diff) |
Merge pull request #114 from lichaofei/master
change the TitleToNumber function
Diffstat (limited to 'lib.go')
-rw-r--r-- | lib.go | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -70,16 +70,21 @@ func ToAlphaString(value int) string { } // TitleToNumber provides function to convert Excel sheet column title to int -// (this function doesn't do value check currently). For example convert AK to -// column title 36: +// (this function doesn't do value check currently). For example convert AK +// and ak to column title 36: // // excelize.TitleToNumber("AK") +// excelize.TitleToNumber("ak") // func TitleToNumber(s string) int { weight := 0.0 sum := 0 for i := len(s) - 1; i >= 0; i-- { - sum = sum + (int(s[i])-int('A')+1)*int(math.Pow(26, weight)) + ch := int(s[i]) + if int(s[i]) >= int('a') && int(s[i]) <= int('z') { + ch = int(s[i]) - 32 + } + sum = sum + (ch-int('A')+1)*int(math.Pow(26, weight)) weight++ } return sum - 1 |