0

我试图使用该软件包xlwings并从一开始就遇到了一个简单的错误。我能够运行他们在此处提供的示例文件而没有任何重大问题(运行代码时打开的多本 Excel 书籍除外),但是当我尝试通过 IPython 执行代码时,我得到了错误AttributeError: Excel.Application.Workbooks。具体来说,我跑了:

from xlwings import Workbook, Sheet, Range, Chart
wb = Workbook()
Range('A1').value = 'Foo 1'

并得到

    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-7-7436ba97d05d> in <module>()
          1 from xlwings import Workbook, Sheet, Range, Chart
    ----> 2 wb = Workbook()
          3 Range('A1').value = 'Foo 1'

    PATH\xlwings\main.pyc in __init__(self, fullname, xl_workbook, app_visible)
        139         else:
        140             # Open Excel if necessary and create a new workbook
    --> 141             self.xl_app, self.xl_workbook = xlplatform.new_workbook()
        142 
        143         self.name = xlplatform.get_workbook_name(self.xl_workbook)

    PATH\xlwings\_xlwindows.pyc in new_workbook()
        103 def new_workbook():
        104     xl_app = _get_latest_app()
    --> 105     xl_workbook = xl_app.Workbooks.Add()
        106     return xl_app, xl_workbook
        107 

   PATH\win32com\client\dynamic.pyc in __getattr__(self, attr)
        520 
        521                 # no where else to look.
    --> 522                 raise AttributeError("%s.%s" % (self._username_, attr))
        523 
        524         def __setattr__(self, attr, value):

    AttributeError: Excel.Application.Workbooks

我注意到这些示例在包含 python 代码的文件夹中已经存在一个 .xlxm 文件。python 代码是否仅在与现有 Excel 文件位于同一位置时才有效?这是否意味着它不能自动创建 Excel 文件?抱歉,如果这是基本的。

4

0 回答 0