Skip to content

Instantly share code, notes, and snippets.

@danmana
Created July 26, 2019 08:52
Show Gist options
  • Save danmana/4b9ad59a05ea5210a09785bf70ca5ba5 to your computer and use it in GitHub Desktop.
Save danmana/4b9ad59a05ea5210a09785bf70ca5ba5 to your computer and use it in GitHub Desktop.
Convert from excel column names to a index (1 based)
'PS'
.split('')
.map(x => x.charCodeAt(0) - 'A'.charCodeAt(0) + 1)
.reduce((acc, v, i, arr) => acc + v * Math.pow('Z'.charCodeAt(0) - 'A'.charCodeAt(0) + 1, arr.length - i - 1), 0);
// A => 1
// Z => 26
// AA => 27
// PS => 435
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment