本文实例讲述了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程序设计有所帮助。
如对本文有疑问, 点击进行留言回复!!
unity的错误解决办法:NullReferenceException: Object reference not set to an instance of an object;tiny proje
Hadoop 之 HDFS (HDFS 数据流的 读写 流程)
听说你一读Spring源码就懵逼?我帮你把架子搭好了,你填就行!
首席架构师推荐:金融保险领域数字化转型实践--如何优雅地修改业务中台中分层应用Maven多模块的版本号?(命令导入式)
[JVM学习之路]一、初识JVM,了解其结构、模型及生命周期
网友评论