Guest User

Untitled

a guest
Jul 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. char c1 = 'A';
  2. c1++; // c1 is 'B' now
  3.  
  4. If Reached_Z Then Add_Another_A
  5.  
  6. public static IEnumerable<string> GetColumns()
  7. {
  8. string s = null;
  9. for (char c2 = 'A'; c2 <= 'Z' + 1; c2++)
  10. {
  11. for (char c = 'A'; c <= 'Z'; c++)
  12. {
  13. yield return s + c;
  14. }
  15. s = c2.ToString ();
  16. }
  17. }
  18.  
  19. string currentCell = "A1";
  20. int currentRow = int.Parse(Regex.Match(currentCell, @"d+").Value);
  21. string currentCol = Regex.Match(currentCell, @"[A-Z]+").Value;
  22. foreach (string column in GetColumns().Where (c => c >= currentCol && currentCol <= "AA"))
  23. {
  24. Console.WriteLine (column + currentRow);
  25. }
  26.  
  27. int columnsToAdd = 26;
  28. currentCell = "C5";
  29. currentRow = int.Parse(Regex.Match(currentCell, @"d+").Value);
  30. currentCol = Regex.Match(currentCell, @"[A-Z]+").Value;
  31. foreach (string column in GetColumns().Where (c => c >= currentCol))
  32. {
  33. if (columnsToAdd--) == 0)
  34. break;
  35. Console.WriteLine (column + currentRow);
  36. }
  37.  
  38. public static string IncrementXLColumn(string Address)
  39. {
  40. var parts = System.Text.RegularExpressions.Regex.Matches(Address, @"([A-Z]+)|(d+)");
  41. if (parts.Count != 2) return null;
  42. return incCol(parts[0].Value) + parts[1].Value;
  43. }
  44.  
  45. private static string incCol(string col)
  46. {
  47. if (col == "") return "A";
  48. string fPart = col.Substring(0, col.Length - 1);
  49. char lChar = col[col.Length - 1];
  50. if (lChar == 'Z') return incCol(fPart) + "A";
  51. return fPart + ++lChar;
  52. }
Add Comment
Please, Sign In to add comment