Skip to content

Commit

Permalink
Merge pull request qax-os#114 from lichaofei/master
Browse files Browse the repository at this point in the history
change the TitleToNumber function
  • Loading branch information
xuri authored Sep 6, 2017
2 parents 5354074 + 1f93fc7 commit cf1077d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cf1077d

Please sign in to comment.