Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char c1 = 'A';
- c1++; // c1 is 'B' now
- If Reached_Z Then Add_Another_A
- public static IEnumerable<string> GetColumns()
- {
- string s = null;
- for (char c2 = 'A'; c2 <= 'Z' + 1; c2++)
- {
- for (char c = 'A'; c <= 'Z'; c++)
- {
- yield return s + c;
- }
- s = c2.ToString ();
- }
- }
- string currentCell = "A1";
- int currentRow = int.Parse(Regex.Match(currentCell, @"d+").Value);
- string currentCol = Regex.Match(currentCell, @"[A-Z]+").Value;
- foreach (string column in GetColumns().Where (c => c >= currentCol && currentCol <= "AA"))
- {
- Console.WriteLine (column + currentRow);
- }
- int columnsToAdd = 26;
- currentCell = "C5";
- currentRow = int.Parse(Regex.Match(currentCell, @"d+").Value);
- currentCol = Regex.Match(currentCell, @"[A-Z]+").Value;
- foreach (string column in GetColumns().Where (c => c >= currentCol))
- {
- if (columnsToAdd--) == 0)
- break;
- Console.WriteLine (column + currentRow);
- }
- public static string IncrementXLColumn(string Address)
- {
- var parts = System.Text.RegularExpressions.Regex.Matches(Address, @"([A-Z]+)|(d+)");
- if (parts.Count != 2) return null;
- return incCol(parts[0].Value) + parts[1].Value;
- }
- private static string incCol(string col)
- {
- if (col == "") return "A";
- string fPart = col.Substring(0, col.Length - 1);
- char lChar = col[col.Length - 1];
- if (lChar == 'Z') return incCol(fPart) + "A";
- return fPart + ++lChar;
- }
Add Comment
Please, Sign In to add comment