从一千多个excel文件中(扩展名是xlsb,不是xlsx),查找【包含指定工作表名称】的文件,并列出文件名称到 汇总.xlsx,python代码如下:
from pyxlsb import open_workbook
import xlsxwriter
import sys,time
t=time.time()
file2=r"汇总.xlsx"
r=1;n=0
wb1=xlsxwriter.Workbook(file2)
ws=wb1.add_worksheet()
with open(r'list.txt','r') as f:
for line in f:
line=line.strip('\n')
try:
with open_workbook(line) as wb:
with wb.get_sheet("UPS历史记录") as sheet:
ws.write("A"+str(r),line)
r+=1
except:
pass
n+=1
wb1.close()
t1=time.time()-t
print("耗时(秒):"+str(t1)+",已处理文件总数:"+str(n))
1658个文件,笔记本电脑配置:i5300U+8G内存+500G机械硬盘,29秒得到结果,有177个文件满足要求。
网友评论