软件编程
位置:首页>> 软件编程>> java编程>> java编程实现根据EXCEL列名求其索引的方法

java编程实现根据EXCEL列名求其索引的方法

作者:jdkleo  发布时间:2022-04-24 03:08:03 

标签:java,EXCEL

本文实例讲述了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程序设计有所帮助。

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com