diff options
author | lichaofei <lichaofei@users.noreply.github.com> | 2017-09-05 19:10:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-05 19:10:23 +0800 |
commit | 363604e2f3775a5cef24eff73ef7e5ab3f7e2587 (patch) | |
tree | 34675d2b9a41103218a2ca402c057b373c2fd00c | |
parent | 5354074fc278e3155a00cc94ec5eb5927e74be7a (diff) | |
parent | 787495c503df509a60c4051eeb297653188bec0a (diff) |
Merge pull request #1 from lichaofei/test
Test
-rw-r--r-- | lib.go | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -70,16 +70,23 @@ 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 +// (this function doesn't do value check currently). For example convert AK(ak、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)) + var ch int + if int(s[i]) >= int('a') && int(s[i]) <= int('z') { + ch = int(s[i]) - 32 + } else { + ch = int(s[i]) + } + sum = sum + (ch-int('A')+1)*int(math.Pow(26, weight)) weight++ } return sum - 1 |