Question

Is there any way to get nth letter of English alphabet? I want smt similar to this:

string letter = EnglishAlphabet.GetLetter(5);
//result -> letter is 'E'

I want to use this according to count of my list. If there is 3 elements on my list so "D:D" is enough for me but there is 4 elements then "E:E". I want use this string here:

 Excel.Range chartRange;    
 Excel.ChartObjects xlCharts = (Excel.ChartObjects)xlWorkSheet.ChartObjects(Type.Missing);
 Excel.ChartObject myChart = xlCharts.Add(5, 5, 540, 160);
 Excel.Chart chartPage = myChart.Chart;    
 chartRange = xlWorkSheet.get_Range("A:A", "D:D");//"D:D" changes according to size of the list??

Any suggestions? Thanks

Was it helpful?

Solution

The simplest approach is:

public string GetLetter(int value)
{
    char letter = (char) ('A' - 1 + value);
    return letter.ToString();
}

I'd personally change the return type to char though:

public char GetLetter(int value)
{
    return (char) ('A' - 1 + value);
}

You might want to put some argument validation on there too though...

OTHER TIPS

In Excel: =CHAR(64+A1) where A1 contains the value of n may suit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top