Sheet列号与数字之间的相互转换
来源:互联网 发布:没网能看电视的软件 编辑:程序博客网 时间:2024/05/22 03:49
一.概述
1. 在sheet中,sheet的列号为A、B。。。Z、AA、AB。。。
2. 但是有时我们想用数字表示列号,就需要字符串与数字之间相互转换
二.方法
1.位置:org.apache.poi.ss.util.CellReference
2.字符串转数字方法
/** * takes in a column reference portion of a CellRef and converts it from * ALPHA-26 number format to 0-based base 10. * 'A' -> 0 * 'Z' -> 25 * 'AA' -> 26 * 'IV' -> 255 * @return zero based column index */ public static int convertColStringToIndex(String ref) { int retval=0; char[] refs = ref.toUpperCase(Locale.ROOT).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 + "'"); } continue; } // Character is uppercase letter, find relative value to A retval = (retval * 26) + (thechar - 'A' + 1); } return retval-1; }3.数字转字符串
/** * Takes in a 0-based base-10 column and returns a ALPHA-26 * representation. * eg column #3 -> D */ public static String convertNumToColString(int col) { // Excel counts column A as the 1st column, we // treat it as the 0th one int excelColNum = col + 1; StringBuilder colRef = new StringBuilder(2); int colRemain = excelColNum; while(colRemain > 0) { int thisPart = colRemain % 26; if(thisPart == 0) { thisPart = 26; } colRemain = (colRemain - thisPart) / 26; // The letter A is at 65 char colChar = (char)(thisPart+64); colRef.insert(0, colChar); } return colRef.toString(); }
阅读全文
0 0
- Sheet列号与数字之间的相互转换
- Excel 列名与列号之间的相互转换
- 数字与百分比之间的相互转换
- 数字与char之间的相互转换
- Excel列名与数字的相互转换
- ip地址在数字与字符串之间的相互转换
- Qt数字与字符串之间的相互转换
- c语言中数字与字符之间的相互转换
- Python数字与字符之间的相互转换
- Qt数字与字符串之间的相互转换
- C语言字符串与数字之间的相互转换
- EXCEL列名与数字之间转换
- 字符串和数字之间的相互转换
- 数字和日期之间的相互转换
- 时间段和数字之间的相互转换
- int的数字与char的数值之间的相互转换
- VBA实现数字列与字母列的相互转化
- 字符串与数字之间的相互转换、判断大小端(用的是union)
- 【PHP】最近用到的工具
- mysql的源码编译
- JAVA解析XML文件
- idea2015 注册激活5种方式
- php中奖概率算法,可用于刮刮卡,大转盘等抽奖算法
- Sheet列号与数字之间的相互转换
- JMeterPlugin 插件安装后,不能跑起来异常 解析(jmeter 3.2)
- hbase中Bytes类的使用
- 解决JDK的安装路径中有空格的情况
- Jedis Object has already been returned to this pool or is invalid
- Caffe(CPU)-Ubuntu16.04下安装教程(未完成)
- php mysql数据库备份
- leetcode--Construct Binary Tree from Preorder and Inorder Traversal
- 蓝桥杯-兰顿蚂蚁(Java)