xlwings无法打开excel报错
最近同事要做大批量同样格式的excel处理,想用python来尝试处理,但是简单的打开文件读取就报错。无语啊。
请求大家帮忙啊。
程序很简单就是网上的教学模板:
import xlwings as xw
app=xw.App(visible=True,add_book=False)
wb=app.books.open(r'F:\test.xlsx')
# wb就是新建的工作簿(workbook),下面则对wb的sheet1的A1单元格赋值
wb.sheets['sheet1'].range('A1').value='苦短'
wb.save()
wb.close()
app.quit()
F:\test.xlsx文件以及建好,用excel可以正常打开。
测试运行报错:
Traceback (most recent call last):
File "D:\python\lib\site-packages\xlwings\_xlwindows.py", line 447, in __call__
return Book(xl=self.xl(name_or_index))
File "D:\python\lib\site-packages\xlwings\_xlwindows.py", line 155, in __call__
v = self._inner(*args, **kwargs)
File "D:\python\lib\site-packages\win32com\client\dynamic.py", line 197, in __call__
return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None)
pywintypes.com_error: (-2147352567, '发生意外。', (0, None, None, None, 0, -2147352565), None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\python\lib\site-packages\xlwings\main.py", line 2974, in open
impl = self.impl(name)
File "D:\python\lib\site-packages\xlwings\_xlwindows.py", line 449, in __call__
raise KeyError(name_or_index)
KeyError: 'test.xlsx'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "F:\open_excel.py", line 3, in <module>
wb=app.books.open(r'F:\test.xlsx')
File "D:\python\lib\site-packages\xlwings\main.py", line 2980, in open
impl = self.impl.open(fullname, update_links, read_only, format, password, write_res_password,
File "D:\python\lib\site-packages\xlwings\_xlwindows.py", line 465, in open
return Book(xl=self.xl.Open(fullname, update_links, read_only, format, password, write_res_password,
File "D:\python\lib\site-packages\xlwings\_xlwindows.py", line 66, in __call__
v = self.__method(*args, **kwargs)
File "<COMObject <unknown>>", line 5, in Open
pywintypes.com_error: (-2147417851, '服务器出现意外情况。', None, None)
[Finished in 23.7s]
完全不知道什么原因,还要花23.7s,而且已经确认F:\test.xlsx没有打开,没有被占用。
但是错误原因完全看不明白。