Created
January 4, 2012 17:57
-
-
Save dnene/1561213 to your computer and use it in GitHub Desktop.
Converting column numbers into excel column headers. Convert integers into strings as follows 0=> "A", 25=>"Z",26=>"AA",701=>"ZZ", 702=>"AAA"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection.mutable.ListBuffer | |
object Coordinates { | |
def main(args: Array[String]): Unit = { | |
println(numToStr(0)) | |
println(numToStr(25)) | |
println(numToStr(26)) | |
println(numToStr(51)) | |
println(numToStr(52)) | |
println(numToStr(700)) | |
println(numToStr(701)) | |
println(numToStr(702)) | |
} | |
def numToStr(i: Int): String = { | |
if (i >= 26) { | |
val n = (i / 26) -1 | |
val d = i % 26 | |
var ret = numToStr(n) | |
ret += (d+65).asInstanceOf[Char] | |
return ret | |
} else { | |
return "" + (i+65).asInstanceOf[Char] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment