python - 如何使用xlwings Python同时打开3个excel文件?
问题描述
我正在尝试打开某个文件夹中的所有 .xlsx 文件。我使用了 xlwings 模块。肯定最后一行代码不正确。你能给我一个提示吗?
import os
import glob
import xlwings as xw
excels = []
for root, dirs, files in os.walk(r'C:\Users\ego\PycharmProjects\TRIAL01\excel files'):
for file in files:
if file.endswith('.xlsx'):
excels.append(file)
for i in excels:
xw.Book(r'C:\Users\ego\PycharmProjects\TRIAL01\excel files', i)
解决方案
这里有一个提示:使用 os.path.join() 方法,因为您当前的字符串将显示为 'C:\Users\ego\PycharmProjects\TRIAL01\excel filesdoc.xlsx' 并且缺少连接反斜杠。
dir = r'C:\Users\ego\PycharmProjects\TRIAL01\excel files'
for i in excels:
xw.Book(os.path.join(dir, i))
推荐阅读
- laravel - 图片不显示在浏览器 Laravel 5.4 上
- visual-studio-2015 - 在 Visual Studio 2015 中构建 openssl_1.0.2p 的问题
- python - 子进程参数列表长
- java - 如何管理通知推送系统
- c# - Excel-Dna C#如何从excel工作表中的选定范围中获取值
- java - 如何将 Java servlet 部署到服务器
- javascript - POSTMAN - 模拟服务器,在示例响应中使用变量
- javascript - 如何找到包含 javascript 属性的元素的 XPath?
- node.js - 更改续集时区
- c# - c#省略嵌套类型参数