如何将列数(如127)转换为一个Excel列(如。AA) [英] How to convert a column number (eg. 127) into an excel column (eg. AA)

查看:108
本文介绍了如何将列数(如127)转换为一个Excel列(如。AA)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你怎么数值数字转换为一个Excel列名在C#中不使用自动化直接从Excel中获取价值。

How do you convert a numerical number to an Excel column name in C# without using automation getting the value directly from Excel.

Excel 2007中有16384个可能的范围是1,这是它支持的列数。所得值应在Excel列名,例如的形式A,AA,AAA等。

Excel 2007 has a possible range of 1 to 16384, which is the number of columns that it supports. The resulting values should be in the form of excel column names, e.g. A, AA, AAA etc.

推荐答案

如果有人需要做这在Excel VBA没有,这里是一个办法:

If anyone needs to do this in Excel without VBA, here is a way:

=SUBSTITUTE(ADDRESS(1;colNum;4);"1";"")

其中colNum是列号​​

where colNum is the column number

而在VBA:

Function GetColumnName(colNum As Integer) As String
    Dim d As Integer
    Dim m As Integer
    Dim name As String
    d = colNum
    name = ""
    Do While (d > 0)
        m = (d - 1) Mod 26
        name = Chr(65 + m) + name
        d = Int((d - m) / 26)
    Loop
    GetColumnName = name
End Function

这篇关于如何将列数(如127)转换为一个Excel列(如。AA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆