System.Diagnostics.Debug.WriteLine(“MESSAGE”);
C# get app settings
ConfigurationManager.AppSettings[someKey] -> return someValue
<configuration>
<appSettings>
<add key=”someKey” value=”someValue”/>
</appSettings>
</configuration>
C# get url parameter
HttpContext.Current.Request.UrlReferrer.Query.Substring(1);
ex)
http://000.000.000.000:0000/index.html?A=B&C=D
-> A=B&C=D
C# TransactionScope timeout
new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromMinutes([minutes]));
C# sql command timeout
SqlCommand.CommandTimeout = [second]
Excel get column index from column name
colIndexToAlpha(27) -> return AA
alphaToColIndex(AA) -> return 27
// get cellReference’s column from column index
public string colIndexToAlpha(int colIndex) {
List<string> colNameList = new List<string>();
int num1 = Convert.ToInt32(colIndex) – 1;
int num2 = 0;
int num3 = 0;
while (true) {
num2 = num1 / 26;
num3 = num1 – 26 * num2;
colNameList.Insert(0, numToAlpha(num3));
if (num2 < 26) {
colNameList.Insert(0, numToAlpha(num2 – 1));
break;
}
num1 = num2;
}
return String.Join(“”, colNameList.ToArray());
}
private String numToAlpha(int number) {
if (number < 0) {
return “”;
}
Char c = (Char)(65 + number);
return c.ToString();
}
// get column index from cellReference’s column
public int alphaToColIndex(string name) {
int index = 0;
for (int i = 0; i < name.Length; i++) {
index *= 26;
index += alphaToNum(name[i]);
}
return index;
}
private int alphaToNum(char alpha) {
return alpha – 64;// A -> 1 Z -> 26
}
private int alphaToNum(string alpha) {
if (alpha.Length != 1) {
return 0;
}
return alpha[0] – 64; // A -> 1 Z -> 26
}
Excel get row index and column name from cell referance
private Regex regexRow = new Regex(@”d+”);
public int getRowIndex(string cellReferance) {
return int.Parse(regexRow.Match(cellName).Value);
}
private Regex regexCol = new Regex(“[A-Za-z]+”);
private string getColumnName(string cellReferance) {
return regexCol.Match(cellName).Value;
}