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 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.
Sorry, this is Python instead of C#, but at least the results are correct:
Easy with recursion.
I'm trying to do the same thing in Java... I've wrote following code:
Now once I ran it with columnNumber = 29, it gives me the result = "CA" (instead of "AC") any comments what I'm missing? I know I can reverse it by StringBuilder.... But looking at the Graham's answer, I'm little confused....
These my codes to convert specific number (index start from 1) to Excel Column.
My Unit Test:
If anyone needs to do this in Excel without VBA, here is a way:
where colNum is the column number
And in VBA:
if you just want it for a cell formula without code, here's a formula for it: