I have some C# code. I'm trying to generate a list of column names in a spreadsheet. In a spreadsheet, cells are listed from left to right starting at "A" and going to something like "ABC". I'm trying to dynamically generate the cell names into a list like this:
var cells = new List<string>();
for (var i=1; i<=5; i++)
{
for (var j = 0; j < 26; j++)
{
var column = "";
for (var k=0; k < i; k++)
{
char letter = Convert.ToChar(j + (int)'A');
column = column + letter;
}
cells.Add(column);
}
}
Unfortunately, my approach isn't working. Once I get past "Z", I immediately see "AA", "BB", "CC", .... Its not looping through alphabet again. What am I doing wrong? I keep staring at it and it looks correct to me. Any help is appreciated.