Excel 列序数转列字母表达
1 function printString(n){ 2 let arr = []; 3 let i = 0; 4 5 // Step 1: Converting to number assuming 6 // 0 in number system 7 while (n) { 8 arr[i] = n % 26; 9 n = Math.floor(n / 26); 10 i++; 11 } 12 13 // Step 2: Getting rid of 0, as 0 is 14 // not part of number system 15 for (let j = 0; j < i - 1; j++) { 16 if (arr[j] <= 0) { 17 arr[j] += 26; 18 arr[j + 1] = arr[j + 1] - 1; 19 } 20 } 21 let ans = ''; 22 for (let j = i; j >= 0; j--) { 23 if (arr[j] > 0) 24 ans += String.fromCharCode(65 + arr[j] - 1); 25 } 26 27 document.write(ans + "<br>"); 28 } 29
printString(26);//Z
printString(51);//
AYprintString(100);//
CV C#实现:
1 static string ColumnIndexToColumnLetter(int colIndex) 2 { 3 int div = colIndex; 4 string colLetter = String.Empty; 5 int mod = 0; 6 7 while (div > 0) 8 { 9 mod = (div - 1) % 26; 10 colLetter = (char)(65 + mod) + colLetter; 11 div = (int)((div - mod) / 26); 12 } 13 return colLetter; 14 }
string columnLetter = ColumnIndexToColumnLetter(100); // returns CV
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 我与微信审核的“相爱相杀”看个人小程序副业
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求