CommonFunction.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Com.Jpsoft.Hospital.ReportClass
  5. {
  6. public class CommonFunction
  7. {
  8. #region 拆分Excel单元格的标记,分为字母和数字两个变量 public static bool getWandD(string Cell,out string W,out string D)
  9. /// <summary>
  10. /// 拆分Excel单元格的标记,分为字母和数字两个变量
  11. /// </summary>
  12. /// <param name="Cell">要拆分的单元格标记</param>
  13. /// <param name="W">返回的列号</param>
  14. /// <param name="D">返回的行号</param>
  15. /// <returns>是否操作成功</returns>
  16. public static bool getWandD(string Cell, out string W, out int D)
  17. {
  18. char tempWord;
  19. W = string.Empty;
  20. D = 0;
  21. try
  22. {
  23. for (int i = 0; i < Cell.Length; i++)
  24. {
  25. tempWord = Convert.ToChar(Cell.Substring(i, 1));
  26. if (tempWord >= 65 && tempWord <= 90)
  27. W = W + tempWord.ToString();
  28. }
  29. D = Convert.ToInt16(Cell.Replace(W, string.Empty));
  30. return true;
  31. }
  32. catch (Exception ex)
  33. {
  34. string errStr;
  35. errStr = ex.Message;
  36. return false;
  37. }
  38. }
  39. #endregion
  40. #region 字母字符串(26进制)和int之间的转换函数 public static int getInt(string strings)和public static string getStrings(int myInts)
  41. /// <summary>
  42. /// 输入26进制的字母字符串返回int
  43. /// </summary>
  44. /// <param name="strings">字母字符串</param>
  45. /// <returns>返回int</returns>
  46. public static int getInt(string strings)
  47. {
  48. int ConvertInt = 0;
  49. char tempC;
  50. for (int i = 0; i < strings.Length; i++)
  51. {
  52. tempC = Convert.ToChar(strings.Substring(i, 1));
  53. ConvertInt = ConvertInt + (tempC - 64) * Convert.ToInt32(Math.Pow(26, strings.Length - 1 - i));
  54. }
  55. return ConvertInt;
  56. }
  57. /// <summary>
  58. /// 输入int返回26进制的字母字符串
  59. /// </summary>
  60. /// <param name="myInts">输入int</param>
  61. /// <returns>返回字母字符串</returns>
  62. public static string getStrings(int myInts)
  63. {
  64. string ConvertStrings = "";
  65. int temp1 = myInts;
  66. int temp2;
  67. for (; temp1 != 0; )
  68. {
  69. temp1 = Math.DivRem(temp1, 26, out temp2);
  70. if (temp2 == 0)
  71. {
  72. ConvertStrings = "Z" + ConvertStrings;
  73. temp1--;
  74. }
  75. else
  76. ConvertStrings = Convert.ToChar(Convert.ToByte(temp2 + 64)).ToString() + ConvertStrings;
  77. }
  78. return ConvertStrings;
  79. }
  80. #endregion
  81. }
  82. }