如何找到对应于给定的整数Excel的列名? [英] How do I find the Excel column name that corresponds to a given integer?

查看:180
本文介绍了如何找到对应于给定的整数Excel的列名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何确定列名的第n列(如阿Q或BH)在Excel中?

How would you determine the column name (e.g. "AQ" or "BH") of the nth column in Excel?

编辑:语言无关的算法来确定这是主要目标,在这里

A language-agnostic algorithm to determine this is the main goal here.

推荐答案

我曾经写过这个函数来执行具体任务:

I once wrote this function to perform that exact task:

public static string Column(int column)
{
    column--;
    if (column >= 0 && column < 26)
        return ((char)('A' + column)).ToString();
    else if (column > 25)
        return Column(column / 26) + Column(column % 26 + 1);
    else
        throw new Exception("Invalid Column #" + (column + 1).ToString());
}

这篇关于如何找到对应于给定的整数Excel的列名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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