Browse Source

Optimize code.

Ri Xu 8 years ago
parent
commit
1f93fc7bad
1 changed files with 3 additions and 5 deletions
  1. 3 5
      lib.go

+ 3 - 5
lib.go

@@ -70,8 +70,8 @@ func ToAlphaString(value int) string {
 }
 }
 
 
 // TitleToNumber provides function to convert Excel sheet column title to int
 // TitleToNumber provides function to convert Excel sheet column title to int
-// (this function doesn't do value check currently). For example convert AK(ak、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")
 //    excelize.TitleToNumber("ak")
 //    excelize.TitleToNumber("ak")
@@ -80,11 +80,9 @@ func TitleToNumber(s string) int {
 	weight := 0.0
 	weight := 0.0
 	sum := 0
 	sum := 0
 	for i := len(s) - 1; i >= 0; i-- {
 	for i := len(s) - 1; i >= 0; i-- {
-		var ch int
+		ch := int(s[i])
 		if int(s[i]) >= int('a') && int(s[i]) <= int('z') {
 		if int(s[i]) >= int('a') && int(s[i]) <= int('z') {
 			ch = int(s[i]) - 32
 			ch = int(s[i]) - 32
-		} else {
-			ch = int(s[i])
 		}
 		}
 		sum = sum + (ch-int('A')+1)*int(math.Pow(26, weight))
 		sum = sum + (ch-int('A')+1)*int(math.Pow(26, weight))
 		weight++
 		weight++