1
1

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.

xlwingsでR1C1参照形式を使う

Posted at

xlwingsのrangeのセル参照は、A1形式は使えるが、R1C1形式は使えない。

import xlwings as xw

xw.Range('A1')   #これは○
xw.Range('R1C1') #これは×

仕方ないので、関数で一度A1形式に変換して、Rangeに渡す。以下の関数を定義。

import xlwings as xw

def toA1(R1C1):
    # Excelが起動している必要あり
    return xw.apps[0].api.ConvertFormula(R1C1, -4150, 1, 4)

使用例

xw.Range(toA1('R1C1:R3C4'))
# xw.Range('A1:D3')と同じ

以下を参考にしました。
R1C1形式をA1形式に変換する

1
1
1

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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?