ExcelConvert
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的更多相关文章
- 转载: 黄聪:C#中 Excel列字母与数字的转换
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Excel列A、B、C、D----与列序号的转换
public static class ExcelConvert { public static int ToExcelIndex(this string columnName) { if (!Reg ...
- [No0000107]C#中 Excel列字母与数字的转换
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
随机推荐
- 使用Phantom omni力反馈设备控制机器人
传统的工业机器人普遍采用电机 .齿轮减速器 .关节轴三者直接连接的传动机构,这种机构要求电机与减速器安装在机械臂关节附近,其缺点是对于多关节机械臂,下一级关节的电机与减速器等驱动装置成为上一级关节的额 ...
- SpringBoot常用属性配置
SpringBoot 2.x:https://github.com/spring-projects/spring-boot/blob/2.0.x/spring-boot-project/spring- ...
- selenium 定制启动 chrome 的选项
序 使用 selenium 时,我们可能需要对 chrome 做一些特殊的设置,以完成我们期望的浏览器行为,比如阻止图片加载,阻止JavaScript执行 等动作.这些需要 selenium的 Chr ...
- 不可不知的Oracle常用技巧
不可不知的Oracle常用技巧 表复制 1.方法一:复制表结构和数据 create table temp_clientloginuser as select distinct userid from ...
- ios 7新特性
1:解决ios7.0中视图控制器中视图坐标布局问题 if ([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0) { self. ...
- Mybaits 使用多数据库源错误 --MapperScannerConfigurer配置
我在配置文件里面配置了一个数据源,数据源参数是根据配置文件加载.数据源在mybaits和自定义数据工具类中使用,但是启动工程后,报错如下: ### Cause: org.springframewor ...
- hihocoder216周:贪心或二分
题目链接 有N条线段,要切K刀,使得最长的线段尽量短.在最佳切割的条件下,切完之后最长的那根绳子是多长. 方法一:贪心 每次切的那一刀必然是最长的那条线段,用优先队列,每次往最长的那条线段上切一刀 方 ...
- selenium的运行时异常
selenium这个库是一个伟大的库,它赋予了程序员控制浏览器的能力.但是如果不理解这个库的设计上的一些哲学,就会遇到很多问题. selenium支持多种浏览器,但是这些浏览器里面,只有firefox ...
- iOS 性能调优
1.内存空间的划分: 我们知道,一个进程占用的内存空间,包含5种不同的数据区:(1)BSS段:通常是存放未初始化的全局变量:(2)数据段:通常是存放已初始化的全局变量.(3)代码段:通常是存放程序执行 ...
- 开发只懂 AFN ?搞定 NSURLSession 才是硬道理
由于傲娇的苹果在 iOS9 之后已经放弃了 NSURLConnection,所以在现在的实际开发中,除了大家常见的 AFN 框架,一般使用的是 iOS7 之后推出的 NSURLSession,作为一名 ...