xlwings Workbook()调用返回AttributeError:Open.Application [英] xlwings Workbook() call returns AttributeError: Open.Application

查看:373
本文介绍了xlwings Workbook()调用返回AttributeError:Open.Application的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望您能帮助我,第一个问题我问自己,但我总是对我在这里找到的专业答案印象深刻!

Hope you can help me out, first question I ask myself but I am always impressed by the professional answers I find here!

我正在使用xlwings从.xls文件读取和写入数据.我不是一个经验丰富的程序员,并且会犯错误.有时,这意味着需要重新启动进程,Python等.

I am using xlwings to both read and write data from .xls files. I am not a seasoned programmer, and I make mistakes. From time to time, this means rebooting processes, Python and what-not.

每一次,我都会在调用Workbook()时得到以下AttributeError.真正的问题不是我不知道发生了什么(我尝试阅读错误诊断参考的模块,但它们是在我无法掌握的Python级别上编写的),而是重新启动甚至重新启动(!)我的笔记本电脑无法(始终)解决问题.

Every now and again, I would get the following AttributeError upon calling Workbook(). The real problem is not that I don't have a clue what is happening (I tried reading the modules the error diagnostics reference to, but they are written on a level of Python that is beyond my skills), but that restarting and even rebooting(!) my laptop don't (always) solve the problem.

我希望能提供一些有关正在发生的事情的线索,但是这似乎是一个随机发生的问题,现在,三次重新启动和几次重新启动并不能解决问题. Google也帮不上忙.我现在必须已经运行了一百次程序,但这并不总是一个问题!错误消息,只需调用Workbook():

I wish I could give some clues as to what is happening, but it appears to be a randomly occurring problem and right now, three reboots and several restarts didn't fix it. Google can't help either. I must have run my program a hundred times by now and it wasn't always a problem! The error message, upon simply calling Workbook():

wb = Workbook()

Traceback (most recent call last):

File "<ipython-input-22-4a3c36eb9bf9>", line 1, in <module>
wb = Workbook()

File "C:\Program Files\Anaconda\lib\site-packages\xlwings\main.py", line 141, in __init__
self.xl_app, self.xl_workbook = xlplatform.new_workbook()

File "C:\Program Files\Anaconda\lib\site-packages\xlwings\_xlwindows.py", line 104, in new_workbook
xl_app = _get_latest_app()

File "C:\Program Files\Anaconda\lib\site-packages\xlwings\_xlwindows.py", line 88, in _get_latest_app
return xl_workbook_current.Application

File "C:\Program Files\Anaconda\lib\site-packages\win32com\client\dynamic.py", line 522, in __getattr__
raise AttributeError("%s.%s" % (self._username_, attr))

AttributeError: Open.Application

作为后续,来自"dyamic.py"的代码段引发了错误:

And as a follow up, the piece of code from 'dyamic.py' raising the error:

[...]
# If we are still here, and have a retEntry, get the OLE item
    if not retEntry is None:
        invoke_type = _GetDescInvokeType(retEntry, pythoncom.INVOKE_PROPERTYGET)
        debug_attr_print("Getting property Id 0x%x from OLE object" % retEntry.dispid)
        try:
            ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
        except pythoncom.com_error, details:
            if details.hresult in ERRORS_BAD_CONTEXT:
                # May be a method.
                self._olerepr_.mapFuncs[attr] = retEntry
                return self._make_method_(attr)
            raise
        debug_attr_print("OLE returned ", ret)
        return self._get_good_object_(ret)

    # no where else to look.
    raise AttributeError("%s.%s" % (self._username_, attr))

正如我之前提到的,最后一点对我来说太麻烦了:P

As I mentioned before, the last bit it too much for me :P

由于一些随机错误,我关闭了一些随机窗口后,我猜想某些挥之不去的Excel.exe(或类似)进程正在干扰脚本,但我无法在任务管理器中找到该脚本.另外,这是重启应解决的问题,对吧?我还升级到了xlwings .34(最新版本,到目前为止).

I guessed some lingering Excel.exe (or similar) process was interfering with the script after I closed some random window due to some random error, but I cant find one in the task manager. Also, this is the kind of thing a reboot should fix, right?! I also upgraded to xlwings .34 (latest version, as of now).

Windows 8.1 64位,Python 2.7(Anaconda发行版,Spyder IDE),Excel 2013.

Windows 8.1 64 bit, Python 2.7 (Anaconda distribution, Spyder IDE), Excel 2013.

当然,非常感谢您的帮助!

Any help is very much appreciated, of course!

非常感谢,

戈登.

根据注释中的建议,我现在可以报告,即使在wb = Workbook()失败时,from win32com.client import dynamic后跟dynamic.Dispatch('Excel.Application')的情况下也会返回<COMObject Excel.Application>.

Following advice given in the comments, I can now report that even at times when wb = Workbook() fails, from win32com.client import dynamic followed by dynamic.Dispatch('Excel.Application') returns <COMObject Excel.Application>.

希望有帮助!

推荐答案

始终检查打开excel工作表的任何问题,例如受密码保护/许可的问题.

Always check either any issues to open the excel sheet, such as password protected/Licensed issues..

如果在打开excel时弹出任何消息,您可能会遇到相同的错误.

If there is any pop up coming while opening excel, you may get the same error.

这篇关于xlwings Workbook()调用返回AttributeError:Open.Application的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆