From 1169042f7db5eb9c85fcce83b9d913e42a6d3a34 Mon Sep 17 00:00:00 2001 From: lichaofei Date: Tue, 5 Sep 2017 18:06:38 +0800 Subject: [PATCH 1/3] Update lib.go --- lib.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib.go b/lib.go index 1bcb8fc..0f1de23 100644 --- a/lib.go +++ b/lib.go @@ -79,7 +79,13 @@ 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 From 787495c503df509a60c4051eeb297653188bec0a Mon Sep 17 00:00:00 2001 From: lichaofei Date: Tue, 5 Sep 2017 18:26:47 +0800 Subject: [PATCH 2/3] Update lib.go --- lib.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib.go b/lib.go index 0f1de23..ab83e50 100644 --- a/lib.go +++ b/lib.go @@ -70,10 +70,11 @@ 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 From 1f93fc7bad0f1a4cd7f3b037a0f370561eae83b1 Mon Sep 17 00:00:00 2001 From: Ri Xu Date: Wed, 6 Sep 2017 12:16:39 +0800 Subject: [PATCH 3/3] Optimize code. --- lib.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib.go b/lib.go index ab83e50..b28b50f 100644 --- a/lib.go +++ b/lib.go @@ -70,8 +70,8 @@ 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(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") @@ -80,11 +80,9 @@ func TitleToNumber(s string) int { weight := 0.0 sum := 0 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') { ch = int(s[i]) - 32 - } else { - ch = int(s[i]) } sum = sum + (ch-int('A')+1)*int(math.Pow(26, weight)) weight++