diff options
author | Nick Burch <nick@apache.org> | 2013-08-23 19:00:01 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2013-08-23 19:00:01 +0000 |
commit | 0c44c5fec787cb0fd81a45eb1aeb53b404e7a2e7 (patch) | |
tree | ad87a605305f1695da0975e3c74c25d8b807a1e7 /src/java/org/apache | |
parent | 57de5b995d3b3ae95cf4374f20beadaf3434d5d3 (diff) | |
download | poi-0c44c5fec787cb0fd81a45eb1aeb53b404e7a2e7.tar.gz poi-0c44c5fec787cb0fd81a45eb1aeb53b404e7a2e7.zip |
More unit tests for column conversion, and avoid the use of Math.pow based on the suggestion from github-6
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1516983 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r-- | src/java/org/apache/poi/ss/util/CellReference.java | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/java/org/apache/poi/ss/util/CellReference.java b/src/java/org/apache/poi/ss/util/CellReference.java index c9bea9fd12..3bd7ba9088 100644 --- a/src/java/org/apache/poi/ss/util/CellReference.java +++ b/src/java/org/apache/poi/ss/util/CellReference.java @@ -170,22 +170,19 @@ public class CellReference { * @return zero based column index */ public static int convertColStringToIndex(String ref) { - - int pos = 0; int retval=0; - for (int k = ref.length()-1; k >= 0; k--) { - char thechar = ref.charAt(k); + char[] refs = ref.toUpperCase().toCharArray(); + for (int k=0; k<refs.length; k++) { + char thechar = refs[k]; if (thechar == ABSOLUTE_REFERENCE_MARKER) { if (k != 0) { throw new IllegalArgumentException("Bad col ref format '" + ref + "'"); } - break; + continue; } - // Character.getNumericValue() returns the values - // 10-35 for the letter A-Z - int shift = (int)Math.pow(26, pos); - retval += (Character.getNumericValue(thechar)-9) * shift; - pos++; + + // Character is uppercase letter, find relative value to A + retval = (retval * 26) + (thechar - 'A' + 1); } return retval-1; } |