Forked from danmana/Excel column name to number.js
Last active
December 30, 2025 03:46
-
-
Save dungsaga/4ea4fd1764e7c41a8421b38fc004b9ef to your computer and use it in GitHub Desktop.
Convert from excel column names to a index (1 based)
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
| function colNum(name = '') { | |
| const val = (c) => c.charCodeAt(0) - 'A'.charCodeAt(0) + 1 | |
| return name.split('') | |
| .reduce((acc, v) => val(v) + acc * val('Z'), 0) | |
| } | |
| colNum('A') === 1 | |
| colNum('Z') === 26 | |
| colNum('AA') === 27 | |
| colNum('AZ') === 52 | |
| colNum('ZZ') === 702 | |
| colNum('AAA') === 703 | |
| colNum('AZA') === 1353 | |
| colNum('ZZZ') === 18278 |
Author
dungsaga
commented
Dec 30, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment