读取所有范围名称和值

时间:2019-02-26 16:28:24

标签: python xlwings

关注Felix的回复: 将referre_to_range.value更改为名称后,我仍然遇到错误。

下面是更新的代码和Jupyter的错误输出。

如果我使用单个范围名称,然后查找值,则可以正常工作,但是当我尝试浏览“ wb.names中的名称”返回的值列表时,无法返回该列表的值。

import xlwings as xw
wb = xw.Book(r'C:\Agency\wkbk utility\Uploaded to HDS\108 Place.xlsm')

for name in wb.names:
    range_value = wb.names(name).name

    print(range_value)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-e5c7c7a0215d> in <module>
      2 
      3 for name in wb.names:
----> 4     range_value = wb.names(name).name
      5 
      6     print(range_value)

~\Anaconda3\lib\site-packages\xlwings\main.py in __call__(self, name_or_index)
   2519 
   2520     def __call__(self, name_or_index):
-> 2521         return Name(impl=self.impl(name_or_index))
   2522 
   2523     def contains(self, name_or_index):

~\Anaconda3\lib\site-packages\xlwings\_xlwindows.py in __call__(self, name_or_index)
   1348 
   1349     def __call__(self, name_or_index):
-> 1350         return Name(xl=self.xl(name_or_index))
   1351 
   1352     def contains(self, name_or_index):

~\Anaconda3\lib\site-packages\xlwings\_xlwindows.py in __call__(self, *args, **kwargs)
    150         for i in range(N_COM_ATTEMPTS + 1):
    151             try:
--> 152                 v = self._inner(*args, **kwargs)
    153                 t = type(v)
    154                 if t is CDispatch:

~\Anaconda3\lib\site-packages\win32com\client\dynamic.py in __call__(self, *args)
    195                 if invkind is not None:
    196                         allArgs = (dispid,LCID,invkind,1) + args
--> 197                         return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None)
    198                 raise TypeError("This dispatch object does not define a default method")
    199 

TypeError: Objects of type 'Name' can not be converted to a COM VARIANT (but obtaining the buffer() of this object could)

0 个答案:

没有答案