Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.
For example
1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB
注意:由于下标从1开始而不是从0开始,因此要减一操作。
static public string ConvertToTitle(int n) {
string s = "";
char c = ‘ ‘;
while (n > 0) {
int num = (n - 1) % 26;
c = Convert.ToChar(num + 65);
s = c + s;
n = (n - 1) / 26;
}
return s;
}
时间: 2024-12-18 09:56:51