This article describes the method of java programming to obtain its index based on EXCEL column names. Share it for your reference, as follows:
principle:
[a1-z26]*26^n-1 + [a1-z26]*26^n-2 + ... + [a1-z26]*26^0
The specific code is as follows:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.util.HashMap; import java.util.Map; /** * * @author jdkleo */ public class ExcelUtil { public static int getCellNum(String cellStr) { char[] cellStrArray = cellStr.toUpperCase().toCharArray(); int len = cellStrArray.length; int n = 0; for(i nt i=0;i<len;i++) { n += (((int)cellStrArray[i])-65+1)*Math.pow(26, len-i-1); } return n-1; } public static void main(String[] args) { System.out.print(getCellNum("aaa")); } }I hope this article will be helpful to everyone's Java programming.