zoukankan      html  css  js  c++  java
  • golang /js index 转换excel字母表头

    Golang

     1 package main
     2 
     3 import "fmt"
     4 
     5 func main() {
     6     var Letters = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
     7     row := 675
     8     result := Letters[row%26]
     9     row = row / 26
    10     for row > 0 {
    11         row = row - 1
    12         result = Letters[row%26] + result
    13         row = row / 26
    14     }
    15     fmt.Println("result==", result)
    16 }

    JS:

     1 function getPostition(index) {
     2     let result = String.fromCharCode(65 + parseInt(index % 26))
     3     let value = index / 26
     4     while (value >= 1) {
     5         value = value - 1
     6         result = String.fromCharCode(65 + parseInt(value % 26)) + result
     7         value = parseInt(value / 26)
     8     }
     9     return result
    10 }
  • 相关阅读:
    例5-6
    例5-5
    例5-4
    例4-5
    例4-4
    例4-3
    例4-2
    例3-11
    例3-10
    例3-9
  • 原文地址:https://www.cnblogs.com/ITCoNan/p/12071426.html
Copyright © 2011-2022 走看看