|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 郭小坤 于 2024-9-26 17:37 编辑
python:往对应的文件夹内添加数据会自动合并:
- import xlrd,os,xlwt
- nwb = xlwt.Workbook('utf-8');nws = nwb.add_sheet('汇总表')
- files = os.listdir('资料汇总需求')
- num, row_num = 0, 2
- [nws.write(1, a, b) for a,b in [[0,'流水号'],[1,'订单号'],[2,'工号'],[3,'姓名'],[4,'特征码'],[5,'项目投入工时'],[6,'当月总工时']]]
- [nws.write(0, k, n) for k,n in [[5,'本月应出席天数'],[6,22]]]
- for file in files:
- wb = xlrd.open_workbook('资料汇总需求/'+ file)
- for ws in wb.sheets():
- for x in tuple(ws.get_rows())[2:]:
- for y in x:
- val = y.value
- nws.write(row_num,num,val)
- print(row_num,num,val)
- num += 1
- row_num += 1
- num = 0
- nwb.save('demo1.xls')
复制代码
|
|