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 ...
随机推荐
- SpringBoot常用属性配置
SpringBoot 2.x:https://github.com/spring-projects/spring-boot/blob/2.0.x/spring-boot-project/spring- ...
- C# 7 out variables, tuples & other new features
C# 7 out variables, tuples & other new features C# 7 is available on new Visual Studio 2017 and ...
- Android 圆角输入框
draweable文件下建立一个名字为shape的XML文件: <shape xmlns:android="http://schemas.android.com/apk/r ...
- rox + openbox + fbpanel + conky打造又快又稳的桌面
从开始用 Gentoo 以来,就没有打算用 gnome . KDE 这些巨无霸级别的 DE ,最后选择了相对来来说比较轻量级的 Xfce4 ,不过最近更是变本加厉,连 Xfce4 都觉得太大.于是,下 ...
- Linux实例安装VNC Server实现图形化访问
引自阿里云: https://help.aliyun.com/knowledge_detail/41530.html
- Debug 路漫漫-04
1.错误使用 cat 要串联的数组的维度不一致. ——前面给个初始化即可: D = cell(length(trainIdx),1); user_itemData = cell(length(trai ...
- linux中DHCP服务配置文件/etc/dhcpd.conf详细说明
DHCP服务的配置 dhcpd.conf 是DHCP服务的配置文件,DHCP服务所有参数都是通过修改dhcpd.conf 文件来实现,安装后dhcpd.conf 是没有做任何配置的,将/usr/sha ...
- nginx无法启动异常
Nginx安装过程中可能会报如下错误: /usr/local/nginx/sbin/nginx -t /usr/local/nginx/sbin/nginx: error while loading ...
- @property的使用方法
参看廖大神的博客 使用@property 有时间整理一下. python 没有私有成员变量的概念,通常在变量前面加单/双下划线来表示私有变量(非共有变量). 通常在python中,以单下划线开始的成员 ...
- selenium实战脚本集(1)——新浪微博发送QQ每日焦点
背景 很多同学在工作中是没有selenium的实战环境的,因此自学的同学会感到有力无处使,想学习但又不知道怎么练习.其实学习新东西的道理都是想通的,那就是反复练习.这里乙醇会给出一些有用的,也富有挑战 ...