for root, dirs, files in os.walk(dir):
for file in files:
lj= os.path.join(root,file)
wb = vb.load_workbook(lj)
gzb = wb.active
list = []
for data in gzb[3]:
if data.value != None:
list.append(data.value)
print(list)
每个文件大概就十行数据,我大概就想要3-10行的数据,有什么好方法能解决吗?
import pandas as pd
df = pd.read_excel(your_file)
df.iloc[3:10+1]
那你别直接遍历呀,通过索引去访问
可以考虑 xlrd 库
#以单个文件为例
wb = xlrd.open_workbook(r'path')
ws=wb.sheet_by_index(0)
nrows1=ws.nrows
list1=[]
for i in range(2,10):
list1.append(ws.row_values(i))
openpyxl的效率注定了他只能成为辅助。我所有数据都是通过pandas操作,然后再由xl输出。