LoginSignup
0
0

More than 3 years have passed since last update.

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

Posted at

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());

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0