1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| public static string Right(this string value, int nb)
{
string col = Regex.Replace(value, "[0-9]", "");
string li = Regex.Replace(value, @"[^\d]", "");
int colInt = col.ColumnIndex();
if (colInt + nb <= 16384)
return (colInt + nb).ColumnLabel() + li;
else
throw new Exception("Incorrect value");
}
public static string Left(this string value, int nb)
{
string col = Regex.Replace(value, "[0-9]", "");
string li = Regex.Replace(value, @"[^\d]", "");
int colInt = col.ColumnIndex();
if (colInt - nb >= 1)
return (colInt - nb).ColumnLabel() + li;
else
throw new Exception("Incorrect value");
}
public static string Up(this string value, int nb)
{
string col = Regex.Replace(value, "[0-9]", "");
string li = Regex.Replace(value, @"[^\d]", "");
if (Int32.Parse(li) - nb >= 1)
return col + (Int32.Parse(li) - nb).ToString();
else
throw new Exception("Incorrect value");
}
public static string Down(this string value, int nb)
{
string col = Regex.Replace(value, "[0-9]", "");
string li = Regex.Replace(value, @"[^\d]", "");
if (Int32.Parse(li) + nb <= 1048576)
return col + (Int32.Parse(li) + nb).ToString();
else
throw new Exception("Incorrect value");
} |
Partager