现在的位置: 首页 > 综合 > 正文

保存一个将Excel里面的列名(A,B,C…)转换为索引号(1,2,3…)的方法

2011年01月08日 ⁄ 综合 ⁄ 共 368字 ⁄ 字号 评论关闭

Google出的含有这个方法的网址是:

http://www.mail-archive.com/poi-user@jakarta.apache.org/msg08811.html

这网站是被墙的。

下面直接贴出方法代码吧,我把它改变成了C#代码,佩服这些涉及数学方面的算法的作者。当然我的老师的数学功力也是我一直顶礼膜拜,只能望其项背,唏嘘感慨的……唉,那个家伙啊!

 1 private int colNameToNum(string colName)
2 {
3 // assume the column name is of uppercase characters
4 int result = 0;
5 for (int i = 0; i < colName.Length; i++)
6 {
7 result = result * 26 + colName[i] - 65 + 1;
8 }
9 return result;
10 }

  

抱歉!评论已关闭.