3 people like it.

get excel column name from zero based column index

excelColumnName 0 = "A" excelColumnName 1 = "B" excelColumnName 545 = "UBB" excelColumnName -1 = exception

1: 
2: 
3: 
4: 
5: 
6: 
7: 
let (|Between|_|) low up i = if i >= low && i <= up then Some () else None
let (|MoreThan|_|) up i = if i > up then Some () else None
let rec excelColumnName zeroBasedIndex =
  match zeroBasedIndex with
  | Between 0 25 -> string ('A' + (char zeroBasedIndex))
  | MoreThan 25  -> excelColumnName(zeroBasedIndex / 26) + excelColumnName(zeroBasedIndex % 26 + 1)
  | _ -> failwithf "couldn't translate %i into excel column name" zeroBasedIndex
val low : 'a (requires comparison)
val up : 'a (requires comparison)
val i : 'a (requires comparison)
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
val excelColumnName : zeroBasedIndex:int -> string

Full name: Script.excelColumnName
val zeroBasedIndex : int
active recognizer Between: 'a -> 'a -> 'a -> unit option

Full name: Script.( |Between|_| )
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
Multiple items
val char : value:'T -> char (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.char

--------------------
type char = System.Char

Full name: Microsoft.FSharp.Core.char
active recognizer MoreThan: 'a -> 'a -> unit option

Full name: Script.( |MoreThan|_| )
val failwithf : format:Printf.StringFormat<'T,'Result> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.failwithf
Raw view Test code New version

More information

Link:http://fssnip.net/7Pq
Posted:7 years ago
Author:Gauthier Segay
Tags: excel , helper , utilities