-
C#教程之C# Net 使用 openxml 写入 对象 到 Excel 中(4)
创建文件:ExcelAlphabet.cs
复制下面全部代码到文件 ExcelAlphabet.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
using DocumentFormat.OpenXml.Spreadsheet; using System; using System.Collections.Generic; using System.Text; namespace YCBX.Office.ExcelXml { /// <summary> /// Excel字母码帮助(26进制转换) /// </summary> public class ExcelAlphabet { //备注 A 对应char为65,Z 对应char为90 /// <summary> /// 26个字母 /// </summary> public static uint AlphabetCount = 26; /// <summary> /// 数字转字符 /// </summary> /// <param name="iNumber"></param> /// <returns></returns> public static string ColumnToABC( int iNumber) { if (iNumber < 1 || iNumber > 702) throw new Exception( "转为26进制可用10进制范围为1-702" ); string sLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; int iUnits = 26; int iDivisor = ( int )(iNumber / iUnits); int iResidue = iNumber % iUnits; if (iDivisor == 1 && iResidue == 0) { iDivisor = 0; iResidue = iResidue + iUnits; } else { if (iResidue == 0) { iDivisor -= 1; iResidue += iUnits; } } if (iDivisor == 0) { return sLetters.Substring(iResidue - 1, 1); } else { return sLetters.Substring(iDivisor - 1, 1) + sLetters.Substring(iResidue - 1, 1); } } /// <summary> /// 字符转数字 /// </summary> /// <param name="sString"></param> /// <returns></returns> public static int ABCToColumn( string sString) { if ( string .Compare(sString, "A" ) == -1 || string .Compare(sString, "ZZ" ) == 1) return 0; string sLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; int iUnits = 26; int sFirst = -1; int sSecond = 0; if (sString.Length == 1) { sSecond = sLetters.IndexOf(sString); } else { sFirst = sLetters.IndexOf(sString.Substring(0, 1)); sSecond = sLetters.IndexOf(sString.Substring(1, 1)); } return (sFirst + 1) * iUnits + (sSecond + 1); } } } |
栏目列表
最新更新
C# 面向对象
假设客车的座位数是9行4列,使用二维数
C#基于接口设计三层架构Unity篇
C#线程 入门
C#读取静态类常量属性和值
C# 插件式编程
C# 委托与事件有啥区别?
C#队列学习笔记:队列(Queue)和堆栈(Stack
linq 多表分组左连接查询查询统计
C#队列学习笔记:MSMQ入门一
C# 在Word中添加Latex 数学公式和符号
inncheck命令 – 检查语法
基于UDP的服务器端和客户端
再谈UDP和TCP
在socket编程中使用域名
网络数据传输时的大小端问题
socket编程实现文件传输功能
如何优雅地断开TCP连接?
图解TCP四次握手断开连接
详细分析TCP数据的传输过程
SqlServer 利用游标批量更新数据
BOS只读状态修改
SQL Server等待事件—PAGEIOLATCH_EX
数据库多行转换为单一列
获取数据表最后最后访问,修改,更新,
计算经历的时间
SQL查询结果自定义排序
修改数据库默认位置
日期简单加或减
从日期获取年,月或日