Xlwings take value from defined names

若如初见. 提交于 2019-12-11 05:01:52

问题


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


回答1:


Sure, just do:

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

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




回答2:


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.



来源:https://stackoverflow.com/questions/43324967/xlwings-take-value-from-defined-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!