Java获取excel中位置

获取Excel列对应的字母位置

    /**
     * 根据列的位置获取列对应的坐标
     * @param index 列的位置 如1对应A
     * @return 字母
     */
    private static String getIndex(Integer index){
        String str = "";
        if(index % 26 == 0 && index != 26) {
            str = getIndex((index-1) / 26);
            index = 26;
        } else if (index > 26) {
            str = getIndex(index / 26);
            index = index % 26;
        }
        char a = 'A';
        for (int i = 1;i<=26;i++) {
            if (i == index) {
                str = str + a;
            }
            a++;
        }
        return str;
    }

 

posted @ 2022-12-29 16:04  白玉神驹  阅读(294)  评论(0)    收藏  举报