public static class ExcelConvert
{
#region - 由数字转换为Excel中的列字母 - public static int ToIndex(string columnName)
{
if (!Regex.IsMatch(columnName.ToUpper(), @"[A-Z]+")) { throw new Exception("invalid parameter"); }
int index = ;
char[] chars = columnName.ToUpper().ToCharArray();
for (int i = ; i < chars.Length; i++)
{
index += ((int)chars[i] - (int)'A' + ) * (int)Math.Pow(, chars.Length - i - );
}
return index - ;
} public static string ToName(int index)
{
if (index < ) { throw new Exception("invalid parameter"); }
List<string> chars = new List<string>();
do
{
if (chars.Count > ) index--;
chars.Insert(, ((char)(index % + (int)'A')).ToString());
index = (int)((index - index % ) / );
} while (index > );
return String.Join(string.Empty, chars.ToArray());
}
#endregion
}

ExcelConvert的更多相关文章

  1. 转载: 黄聪:C#中 Excel列字母与数字的转换

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  2. Excel列A、B、C、D----与列序号的转换

    public static class ExcelConvert { public static int ToExcelIndex(this string columnName) { if (!Reg ...

  3. [No0000107]C#中 Excel列字母与数字的转换

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

随机推荐

  1. Axure 地区选择(选择省份之后可以选择对应的地级市)

    百度网盘:http://pan.baidu.com/s/1c1ZjUPq

  2. RHEL7禁用网卡命名规则

    [root@rhel7 ~]# vi /etc/sysconfig/grub GRUB_TIMEOUT= GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g ...

  3. 基于Pygame写的翻译方法

    发布时间:2018-11-01   技术:pygame+easygui   概述 实现一个翻译功能,中英文的互相转换.并可以播放翻译后的内容. 翻译接口调用的是百度翻译的api接口. 详细 代码下载: ...

  4. Spring 多数据源事务配置问题

    2009-12-22 在SpringSide 3 中,白衣提供的预先配置好的环境非常有利于用户进行快速开发,但是同时也会为扩展带来一些困难.最直接的例子就是关于在项目中使用多个数据源的问题,似乎 很难 ...

  5. 不让复制是不可能的----js获取选中文字

    在360百科.知乎上经常会遇见禁止复制文本的情形,这能挡住一部分人复制,却挡不住程序员的复制. HTML都给我了,难道一小段文本我都拿不下来吗? F12打开控制台,然后选中文本,在控制台下粘贴以下代码 ...

  6. Python实现鸢尾花数据集分类问题——使用LogisticRegression分类器

    . 逻辑回归 逻辑回归(Logistic Regression)是用于处理因变量为分类变量的回归问题,常见的是二分类或二项分布问题,也可以处理多分类问题,它实际上是属于一种分类方法. 概率p与因变量往 ...

  7. JavaScript 错误处理, Throw、Try 和 Catch入门

    try 语句测试代码块的错误. catch 语句处理错误. throw 语句创建自定义错误. 错误一定会发生 当 JavaScript 引擎执行 JavaScript 代码时,会发生各种错误: 可能是 ...

  8. Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 2611816 bytes)

    一段PHP程序执行报错: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 261181 ...

  9. zabbix v3.0安装部署

    这篇文章没有写明init的部分要注意 zabbix v3.0安装部署 摘要: 本文的安装过程摘自http://www.ttlsa.com/以及http://b.lifec-inc.com ,和站长凉白 ...

  10. 用STS和Maven的方式创建一个JavaWeb项目

    一.创建项目 1.Eclipse中用Maven创建项目,选maven-archetype-webapp,如下图: 创建好项目后,目录如下: 至此,项目已经创建完毕,下边是配置.关键所在!!! 二.项目 ...