public class XZou {
private final static String rows = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/**
* 根据Excel列下标得到相应的编码,如2对应C
* @param value
* @return
*/
public static String getCellCode(int value){
if(value/25<1){
return String.valueOf(rows.charAt(value));
}else{
int cj = value/26;
if(cj==0){
return String.valueOf(rows.charAt(value));
}
int mod = value%26;
return String.valueOf(rows.charAt(cj-1)) + String.valueOf(rows.charAt(mod));
}
}
/**
* 根据列字母得出相应的下标值,例 C,2。 或者您也可以使用 apache POI 中的 这个类去获取 org.apache.poi.hssf.util.CellReference
* @param s, Excel 列字母
* @return 列下标
*/
public int getColNum(String s) {
if (s.length() == 1) {
return rows.indexOf(s);
}
return 26 * (rows.indexOf(s.substring(0, 1)) + 1)
+ getColNum(s.substring(1, s.length()));
}
}
Excel中列号对应数字或数字对应列号
最新推荐文章于 2021-01-11 19:44:55 发布