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.
This is a javascript version according to Graham's code
In Delphi (Pascal):
You might need conversion both ways, e.g from Excel column adress like AAZ to integer and from any integer to Excel. The two methods below will do just that. Assumes 1 based indexing, first element in your "arrays" are element number 1. No limits on size here, so you can use adresses like ERROR and that would be column number 2613824 ...
Another VBA way
This is the question all others as well as Google redirect to so I'm posting this here.
Many of these answers are correct but too cumbersome for simple situations such as when you don't have over 26 columns. If you have any doubt whether you might go into double character columns then ignore this answer, but if you're sure you won't, then you could do it as simple as this in C#:
Heck, if you're confident about what you're passing in you could even remove the validation and use this inline:
This will be very similar in many languages so you can adapt it as needed.
Again, only use this if you're 100% sure you won't have more than 26 columns.
Sorry, this is Python instead of C#, but at least the results are correct:
Passed these test cases: