How to convert a column number (e.g. 127) into an Excel column (e.g. AA)

前端 未结 30 2608
鱼传尺愫
鱼传尺愫 2020-11-22 00:35

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 has a possible range o

30条回答
  •  余生分开走
    2020-11-22 00:46

    private String getColumn(int c) {
        String s = "";
        do {
            s = (char)('A' + (c % 26)) + s;
            c /= 26;
        } while (c-- > 0);
        return s;
    }
    

    Its not exactly base 26, there is no 0 in the system. If there was, 'Z' would be followed by 'BA' not by 'AA'.

提交回复
热议问题