-
-
Save kawanet/69237038ea3c414284a5418d732b5660 to your computer and use it in GitHub Desktop.
Excel の AA 形式のカラム名と配列インデックスを相互変換する JavaScript
This file contains 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
/** | |
* Excel Column: A,B,C,...,Z,AA,AB,...,XFC,XFD | |
* Column Index: 0,1,2,...,25,26,27,...,16382,16383 | |
*/ | |
const col2idx = c => c.split("").reduce((prev, c) => (prev * 26 + parseInt(c, 36) - 9), 0) - 1; | |
const idx2col = n => ((n > 25 ? idx2col(Math.floor(n / 26 - 1)) : "") + (n % 26 + 10).toString(36).toUpperCase()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment