Xlwings take value from defined names

2019-07-28 20:37发布

I have an excel with a defined name, cell A1 has assigned name "myName" is there a way with xlwings to take its content from its name rather than on its coordinates?

It should be the same of

    title, coord = next(wb.defined_names['myName'].destinations)
content = wb[title][coord].value

in openpyxls

2条回答
ゆ 、 Hurt°
2楼-- · 2019-07-28 21:24

Using xlwings, very similarly to VBA, you could use the following

range_object = wb.names("named_range").refers_to_range
range_value = wb.names("named_range").refers_to_range.value

As mentioned by Felix, the http://docs.xlwings.org/en/stable/api.html#name page has the answer. Unfortunately, there are no examples of how to access the named range without first specifying a worksheet. I hope my explanation helps.

查看更多
混吃等死
3楼-- · 2019-07-28 21:30

Sure, just do:

import xlwings as xw
xw.sheets[0].range('myName').value

See also: http://docs.xlwings.org/en/stable/api.html#name

查看更多
登录 后发表回答