如何将列号(例如127)转换为Excel列(例如AA) [英] How to convert a column number (e.g. 127) into an Excel column (e.g. AA)

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

问题描述

如何在不使用自动化的情况下将数字转换为C#中的Excel列名直接从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的可能范围为1到16384,这是它支持的列数。结果值应采用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.

推荐答案

如果有人需要在没有VBA的Excel中执行此操作,则可以使用以下方法:

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天全站免登陆