# 批量的读取某文件夹下的每个Excel文件数据
# 获取某个文件下所有Excel文件的路径
# 标准库 os
import os
import xlrd
path = r"C:\Users\Administrator\Desktop\自动化"
all_filename = os.listdir(path)
all_filepath = []
for filepath in all_filename:
# 链路拼接:
filepath = os.path.join(path, filepath)
print(filepath)
# 链路拼接:
filepath = os.path.join(path, filepath)
all_filepath.append(filepath)
print(all_filepath)
#初始化列表
content = []
for file in all_filepath:
data =xlrd.open_workbook(file)
table = data.sheets()[0]
#获取 用户名 回答1 回答2
#1.用户名:从路径中 提取 用户名 刘六
username = print(file.split("\\")[-1].split("."))
#2.获取回答1 模板固定的获取单元格值
auswerl1=table.cell_value(rowx=4,colx=4)
#3.获取回答2
auswerl2=table.cell_value(rowx=10,colx=4)
# print(username,auswerl1,auswerl2)
#将数据以行为单位:用户名,回答1,回答2
temp = [username,auswerl1,auswerl2]
#print(temp)
content.append(temp)
print(content)