I want to create an instance of the Cell class, naming the cell instance with a name like "A", "B", "C", etc., as in an Excel spreadsheet.
I have a Cell class:
public class Cell { public Cell(Range nativeCell) { NativeCell = nativeCell; } public Range NativeCell { get; private set; } }
And my Sheet class:
public class Sheet { private IDictionary<string, Cell> _cells; public Sheet(Worksheet nativeSheet) { NativeSheet = nativeSheet; _cells = new Dictionary<string, Cell>(); for (int rowIndex = 1; rowIndex <= NativeSheet.Rows.Count; ++rowIndex) for (int colIndex = 1; colIndex <= NativeSheet.Columns.Count; ++colIndex) { ICell newCell = new Cell(NativeSheet.Cells(rowIndex, colIndex)); newCell.Name = ??
I need to create a name based on the letters and double and triple them as soon as I run into the last letter of the alphabet "Z". The algorithm would have to generate letters, which I would associate with the rowIndex value, which would lead to this naming strategy such as Excel.
The letters will be as follows:
A, B, C, D...Z, AA, AB, AC...AZ, BA, BB, BC...BZ, CA...XAA, XAB, XAC...
Although we clearly know that a value of colIndex 1 will necessarily indicate a column "A", a value of 2 = "B", a value of 3 = "C", etc.
My problem especially is that we double the letters.
Do you have any ideas on how I could achieve this in its simplest form?
Thanks! =)