for i in file_list: if os.path.splitext(i)[1] == '.xlsx': try: workbooks = xw.Book(file_path + '\\' + i)优化代码 隐藏打开
时间: 2024-05-05 14:17:24 浏览: 88
详谈Python3 操作系统与路径 模块(os / os.path / pathlib)
for i in file_list:
if os.path.splitext(i)[1] == '.xlsx':
try:
with xw.App(visible=False) as app:
workbook = app.books.open(os.path.join(file_path, i))
except xw.exceptions.XlwingsError:
print(f"Error opening {i}")
else:
# Do something with the workbook
workbook.close()
```
阅读全文