引用
Console Log 如下
Building in workspace D:\00_code\04_xlwings
[04_xlwings] $ cmd /c call C:\Windows\TEMP\jenkins7142266595008192231.bat
D:\00_code\04_xlwings>cd D:\00_code\04_xlwings
D:\00_code\04_xlwings>python64 01_xlwings.py
D:\00_code\04_xlwings
Traceback (most recent call last):
File "D:\Python38_64\lib\site-packages\xlwings\_xlwindows.py", line 505, in __call__
return Book(xl=self.xl(name_or_index))
File "D:\Python38_64\lib\site-packages\xlwings\_xlwindows.py", line 169, in __call__
v = self._inner(*args, **kwargs)
File "C:\Windows\TEMP\gen_py\3.8\00020813-0000-0000-C000-000000000046x0x1x8.py", line 39136, in __call__
ret = self._oleobj_.InvokeTypes(0, LCID, 2, (13, 0), ((12, 1),),Index
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:\Python38_64\lib\site-packages\xlwings\main.py", line 4358, in open
impl = self.impl(name)
File "D:\Python38_64\lib\site-packages\xlwings\_xlwindows.py", line 507, in __call__
raise KeyError(name_or_index)
KeyError: 'a.xls'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "01_xlwings.py", line 8, in <module>
wb = app.books.open('D:\\00_code\\04_xlwings\\a.xls')
File "D:\Python38_64\lib\site-packages\xlwings\main.py", line 4364, in open
impl = self.impl.open(fullname, update_links, read_only, format, password, write_res_password,
File "D:\Python38_64\lib\site-packages\xlwings\_xlwindows.py", line 523, in open
return Book(xl=self.xl.Open(fullname, update_links, read_only, format, password, write_res_password,
File "D:\Python38_64\lib\site-packages\xlwings\_xlwindows.py", line 72, in __call__
v = self.__method(*args, **kwargs)
File "C:\Windows\TEMP\gen_py\3.8\00020813-0000-0000-C000-000000000046x0x1x8.py", line 39013, in Open
ret = self._oleobj_.InvokeTypes(1923, LCID, 1, (13, 0), ((8, 1), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17)),Filename
pywintypes.com_error: (-2147352567, '发生意外。', (0, 'Microsoft Excel', 'Microsoft Excel 不能访问文件“D:\\00_code\\04_xlwings\\a.xls”。 可能的原因有以下几个:\n\n\u2022 文件名称或路径不存在。\n\u2022 文件正被其他程序使用。\n\u2022 您正要保存的工作簿与当前打开的工作簿同名。', 'xlmain11.chm', 0, -2146827284), None)
D:\00_code\04_xlwings>exit 1
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
- 问题描述
- windows 下配置Jenkins服务器,采用python调用xlwings 读写MS Excel
- 一旦调用Open函数就会引发pywintypes.com_error
- 测试代码
import xlwings as xw
import time
import os
app = xw.App(visible=False, add_book=True)
pwd = os.getcwd()
print(pwd)
wb = app.books.open('D:\\00_code\\04_xlwings\\a.xls')
time.sleep(10)
wb.close()
app.quit()
- 解决办法
解决办法来自导出Excel出现Microsoft Office Excel 不能访问文件 (360doc.com)
- 打开组件服务 如何打开系统组件服务-百度经验 (baidu.com)
- 找到Microsoft Excel Application服务,点击“标识”,选择“交互式用户”
- 点击“安全”标签, 在“启动和激活权限”上点击“自定义”,然后点击对应的“编辑”按钮,在弹出的“安全性”对话框中添加一个“NETWORK SERVICE”用户(注意要选择本计算机名),并给它赋予“本地启动权限”和“本地激活”权限
- 按照3的方法,修改“访问权限”