Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

Excel の AA 形式のカラム名と配列インデックスを相互変換する JavaScript

Excel では、列名が A・B・C・・・Y・Z・AA・AB・・・XFC・XFD 形式にで表示されます。
配列のインデックス(添字)と列名を相互変換する JavaScript ワンライナー。↓

// Excel Column to Index
const col2idx = c => c.split("").reduce((prev, c) => (prev * 26 + parseInt(c, 36) - 9), 0) - 1;

// Index to Excel Column
const idx2col = n => ((n > 25 ? idx2col(Math.floor(n / 26 - 1)) : "") + (n % 26 + 10).toString(36).toUpperCase());

https://gist.github.com/kawanet/69237038ea3c414284a5418d732b5660

kawanet
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away