[英]seaching all excel files with os.walk (), then call the function to read this excel, How can I do it?
I created a function to read excel sheet read_Excel_file(path) that return a list contains some data from a specific Column. 我创建了一个读取Excel工作表read_Excel_file(path)的函数,该函数返回一个列表,其中包含来自特定列的一些数据。
and in the main code I search all the excel files (where the name start Design) and this excel file should be saved in a folder Design
. 然后在主代码中搜索所有excel文件(名称以Design开头),并且此excel文件应保存在
Design
文件夹中。 If I find the excel file, I call the function read_Excel_file
. 如果找到excel文件,则调用函数
read_Excel_file
。
Please find below the code: 请在下面的代码中找到:
import openpyxl as opx
import os
for r, d, f in os.walk('.'):
for file in f:
if '.xlsx' and 'design' in file:
#print(r)
if r.endswith('\Design'):
print(file)
read_Excel_file(file)
but I get the error : 但我得到了错误:
No such file or directory
无此文件或目录
even if I am sure that I have this file in my directory 即使我确定我的目录中有此文件
Do you think that I have path problem? 你认为我有路径问题吗?
PS: I add print(file)
just to check the name of the file, but when read_Excel_file(file)
after that I have the error. PS:我添加
print(file)
只是为了检查print(file)
的名称,但是当read_Excel_file(file)
之后的read_Excel_file(file)
出现错误时。
Can you help me please? 你能帮我吗?
File is just the name of the file. 文件只是文件名。 You are missing the complete adress.
您缺少完整的地址。 You need to add the root part of the address.
您需要添加地址的根部分。
Just do: 做就是了:
filepath = os.path.join(r, file)
read_Excel_file(filepath)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.