问题
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