本文實例講述了java編程實現根據EXCEL列名求其索引的方法。分享給大家供大家參考,具體如下:
原理:
[a1-z26]*26^n-1 + [a1-z26]*26^n-2 + ... + [a1-z26]*26^0
具體代碼如下:
/* * 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(int 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")); } }
希望本文所述對大家java程序設計有所幫助。
新聞熱點
疑難解答