惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
博客园 - 聂微东
Jina AI
Jina AI
The Cloudflare Blog
V
Visual Studio Blog
博客园_首页
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 【当耐特】
爱范儿
爱范儿
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
博客园 - 司徒正美
阮一峰的网络日志
阮一峰的网络日志
Last Week in AI
Last Week in AI
V
V2EX
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 叶小钗
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
博客园 - Franky

博客园 - 10cn.net

expdp/impdp 远程DB访问(跨服务器创建DB连接) DIV居中(水平&垂直) PHPMailer&Gmail FOR vROW_CUR IN vCUR(PARA1, PARA2) LOOP の使い方 JavaScript Trim IE6中,一个Button同时打开两个下载窗口,并且可以自动关闭 Oracle中复制表结构和表数据 Excel 列号转换为字母(VBA) VS在进行调试时,不能调试的原因列举如下 Create User OS中9个是危险较大的服务 .Net开发人员应该下载的十种必备工具 IIS 中 "另一个程序正在使用此文件,进程无法访问!" JS页面刷新 批处理命令学习(二) 批处理命令学习(一) clean_vss_files.bat Oracle: import tables use .dmp file in PL/SQL Developer
Excel列字母与数字的转换
10cn.net · 2009-07-09 · via 博客园 - 10cn.net

最近工作中发现需要转换Excel列名,例如A列序号为0,Z列序号为25,ZB列则为27
发现字母列名实际为26进制,于是写了如下Helper Class来解决我的问题:

 1 public class ExcelColumnTranslator
 2 {
 3     private ExcelColumnTranslator()
 4     { 
 5     }
 6 
 7     public static int ToIndex(string columnName)
 8     {
 9         if (!Regex.IsMatch(columnName.ToUpper(), @"[A-Z]+"))
10             throw new Exception("invalid parameter");
11         int index = 0;
12         char[] chars = columnName.ToUpper().ToCharArray();
13         for (int i = 0; i < chars.Length; i++)
14         {
15             index += ((int)chars[i] - (int)'A' + 1* (int)Math.Pow(26, chars.Length - i - 1);
16         }
17         return index - 1;
18     }
19 
20     public static string ToName(int index)
21     {
22         if (index < 0)
23             throw new Exception("invalid parameter");
24         List<string> chars = new List<string>();
25         do
26         {
27             if (chars.Count > 0) index--;
28             chars.Insert(0, ((char)(index % 26 + (int)'A')).ToString());
29             index = (int)((index - index % 26/ 26);
30         } while (index > 0);
31         
32         return String.Join(string.Empty, chars.ToArray());
33     }
34 }
35 

PHP相关参考:http://www.liuyuanjun.com/internet/php-letter-add-function/