1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace Com.Jpsoft.Hospital.ReportClass
- {
- public class CommonFunction
- {
- #region 拆分Excel单元格的标记,分为字母和数字两个变量 public static bool getWandD(string Cell,out string W,out string D)
- /// <summary>
- /// 拆分Excel单元格的标记,分为字母和数字两个变量
- /// </summary>
- /// <param name="Cell">要拆分的单元格标记</param>
- /// <param name="W">返回的列号</param>
- /// <param name="D">返回的行号</param>
- /// <returns>是否操作成功</returns>
- public static bool getWandD(string Cell, out string W, out int D)
- {
- char tempWord;
- W = string.Empty;
- D = 0;
- try
- {
- for (int i = 0; i < Cell.Length; i++)
- {
- tempWord = Convert.ToChar(Cell.Substring(i, 1));
- if (tempWord >= 65 && tempWord <= 90)
- W = W + tempWord.ToString();
- }
- D = Convert.ToInt16(Cell.Replace(W, string.Empty));
- return true;
- }
- catch (Exception ex)
- {
- string errStr;
- errStr = ex.Message;
- return false;
- }
- }
- #endregion
- #region 字母字符串(26进制)和int之间的转换函数 public static int getInt(string strings)和public static string getStrings(int myInts)
- /// <summary>
- /// 输入26进制的字母字符串返回int
- /// </summary>
- /// <param name="strings">字母字符串</param>
- /// <returns>返回int</returns>
- public static int getInt(string strings)
- {
- int ConvertInt = 0;
- char tempC;
- for (int i = 0; i < strings.Length; i++)
- {
- tempC = Convert.ToChar(strings.Substring(i, 1));
- ConvertInt = ConvertInt + (tempC - 64) * Convert.ToInt32(Math.Pow(26, strings.Length - 1 - i));
- }
- return ConvertInt;
- }
- /// <summary>
- /// 输入int返回26进制的字母字符串
- /// </summary>
- /// <param name="myInts">输入int</param>
- /// <returns>返回字母字符串</returns>
- public static string getStrings(int myInts)
- {
- string ConvertStrings = "";
- int temp1 = myInts;
- int temp2;
- for (; temp1 != 0; )
- {
- temp1 = Math.DivRem(temp1, 26, out temp2);
- if (temp2 == 0)
- {
- ConvertStrings = "Z" + ConvertStrings;
- temp1--;
- }
- else
- ConvertStrings = Convert.ToChar(Convert.ToByte(temp2 + 64)).ToString() + ConvertStrings;
- }
- return ConvertStrings;
- }
- #endregion
- }
- }
|