Commit c6aed539 authored by yanzg's avatar yanzg

修改实体位置

parent 7c1656d0
...@@ -38,6 +38,28 @@ public class CalcHelper { ...@@ -38,6 +38,28 @@ public class CalcHelper {
} }
/**
* 获取excel列序号
*
* @param columnName
* @return
*/
public static final int getExcelIndex(String columnName) {
columnName = columnName.toLowerCase();
if (!columnName.matches("^[a-z]+$")) {
throw new RuntimeException("变量名" + columnName + "不支持");
}
// 从名称转换列序号
int formulaColumnIndex = 0;
char[] chs = new char[columnName.length()];
columnName.getChars(0, columnName.length() , chs, 0);
for (int i = 0; i < chs.length; i++) {
formulaColumnIndex = formulaColumnIndex * 26 + (chs[i] - 'a' + 1);
}
formulaColumnIndex--;
return formulaColumnIndex;
}
/** /**
* 计算公式 * 计算公式
* *
......
...@@ -43,4 +43,12 @@ public class TestCalcHelper { ...@@ -43,4 +43,12 @@ public class TestCalcHelper {
} }
})); }));
} }
@Test
public void test2() {
System.out.println(CalcHelper.getExcelIndex("aa"));
System.out.println(CalcHelper.getExcelIndex("ba"));
System.out.println(CalcHelper.getExcelIndex("ab"));
System.out.println(CalcHelper.getExcelIndex("a"));
}
} }
aa
王蕾 王蕾
陈俊 陈俊
06151196 06151196
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment