无法通过python打开Excel文档

时间:2014-11-04 15:31:00

标签: python excel win32com

我不是一个非常高级的python用户,并且正在处理我正在处理的程序。我能够在一台计算机上无故障地工作,但现在当我尝试在另一台计算机上运行时,它无法正常工作。

基本上我正在尝试打开一个excel文件并将内容写入其中然后保存为。

这是错误

   Traceback (most recent call last):
  File "C:\Users\aainstall\Desktop\Python\DD\DDcreatemacrosheets10_27_14.py", line 70, in <module>
    wb = excel.Workbooks.Open("Allmacro.xlsx")
  File "C:\Python34\lib\site-packages\win32com\gen_py\00020813-0000-0000-C000-000000000046x0x1x7\Workbooks.py", line 78, in Open
    , Converter, AddToMru, Local, CorruptLoad)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', "'Allmacro.xlsx' could not be found. Check the spelling of the file name, and verify that the file location is correct.\n\nIf you are trying to open the file from your list of most recently used files, make sure that the file has not been renamed, moved, or deleted.", 'xlmain11.chm', 0, -2146827284), None)

以下是相关代码。

import xlrd
import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')


for i in ListofDDlists:
    cellnumber = 0

    if i == AllCD:
        wb = excel.Workbooks.Open("Allmacro.xlsx")
        print (wb)
        excel.Visible = True
        ws = wb.Worksheets("MyData")

我很困惑这个问题可能是什么,并且即将修复它。它正在寻找的文件就在那里,并且位于正确的位置。所以我不确定问题是什么。

我尝试运行此计算机的两台计算机都使用的是Windows 7.这种计算机使用的是Python 3.3,而它不能使用的计算机使用的是Python 3.4。两台计算机都安装了Excel 2010。

0 个答案:

没有答案
相关问题