3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

openpyxl と xlwings の名前付き範囲

Last updated at Posted at 2018-02-13

よく使う API の比較

openpyxl xlwings 内容
px.workbook.defined_name.DefinedNameList xw.main.Names Names 型相当
px.workbook.defined_name.DefinedName xw.main.Name Name 型相当
names = wb.defined_names names = wb.names Workbook.Names 相当
name = names['ブック単位範囲名'] name = names['ブックorシート単位範囲名'] ネーム情報
name = names.get('ブック単位範囲名')
name = names.get('シート単位範囲名', False)
name.attr_text name.refers_to[1:] アドレスを得る
[wb[s][r] for s, r in name.destinations] name.refers_to_range セルor範囲を得る

サンプル

openpyxlサンプル

本家説明 がざっくり過げててアレ。

names = wb.defined_names
name = names['ブック単位範囲名']
name = names.get('ブック単位範囲名')
name = names.get('シート単位範囲名', False)
cells = [wb[s][r] for s, r in name.destinations]

# シートインスタンスからも手繰れるが deprecated 扱いになっている
cells = wb['シート名'].get_named_range('ブック単位範囲名')

xlwingsサンプル

rng = wb.sheets['シート名']['範囲名']
3
4
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
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?