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 ...
随机推荐
- js 正则表达式校验必须包含字母、数字、特殊字符
1.情景展示 在注册时,密码要求必须同时包含:字母.数字.特殊字符,如何实现? 2.原因分析 用正则表达式进行校验,是最方便的! 3.解决方案 // 密码必须由 8-64位字母.数字.特殊符号组成 ...
- 【BI】OLTP与OLAP的区别
概念 OLTP:联机事务处理(On-Line transaction Processing) OLAP:联机分析处理(On-Line Analytical Processing) (1)OLTP是传统 ...
- Fix: Windows Script Host access is disabled on this machine
If you receive this Windows Script Host access is disabled on this machine, Contact your administrat ...
- Inno Setup入门(二)——修改安装过程中的图片
修改安装过程中的图片 一般编译之后,安装过程中出现在左边图片是是下图这个样子的: 其实也可以修改它,只需要在setup段中作一点稍微的修改,加一行代码即可: [setup] AppName=Test ...
- 基于源码编译安装openssh
最近的,openssl/openssh等相继漏洞的暴露,让暴露在公网的linux.沦陷为肉鸡的正营... 没办法,还是升级版本... 00.openssh简介 OpenSSH 是一组安全远程的连接工 ...
- spring aop实现日志收集
概述 使用spring aop 来实现日志的统一收集功能 详细 代码下载:http://www.demodashi.com/demo/10185.html 使用spring aop 来实现日志的统一收 ...
- QQ登录整合/oauth2.0认证-01-申请appkey和appid
本节需要你申请appkey和appid还有绑定域名的空间 首先 再讲课之前 你需要准备以下东西 到腾讯开发平台中申请 开发者 获得appid 和appkey 这两个东东 这两个东东 就算没审核 也可以 ...
- CentOS6.6安装S******Sockets服务端
1.查看系统 [root@localhost ~]# cat /etc/issue CentOS release 6.6 (Final) [root@localhost ~]# uname -a Li ...
- 要成为linux网站运维工程师必须要掌握的技能
要成为linux网站运维工程师必须要掌握的技能 2015-07-27 发表 老男孩点评:感谢此文的作者,写的非常到位,值得入门的初学者认真看看 我是一名linux运维工程师,确切的说是网站运维工程师, ...
- 我的学习工作经历,一个园林专业中专毕业生的IT之路 学习编程 创业
我的学习工作经历,一个园林专业中专毕业生的IT之路 魏琼东,男,1983年生人,祖籍甘肃陇南人,首先得感谢我父亲给我取了这么一个好名字,至少我非常喜欢他,因为目前还没有发现和我同名的人. 我是1998 ...