同一文件夹下多工作簿内多sheet合并,且末列写入工作簿名称.py

#同一文件夹下多工作簿内多sheet合并,且末列写入工作簿名称
#注意:xlrd==1.2.0
print("* * * * * *正在处理请稍后 * * * * * *\n")
# -*- coding: utf-8 -*-
import os,xlrd,xlsxwriter
filePath = r'C:\Users\xoadmin\Desktop\报表'
f_name = os.listdir(filePath)
source_xlsx= []
for i in f_name:
source_xlsx.append(filePath + '\\' + i)
target_xlsx = r"C:\Users\xoadmin\Desktop\报表.xlsx"
data = []
for i in source_xlsx:
wb = xlrd.open_workbook(i)
for sheet in wb.sheets():
for rownum in range(sheet.nrows):
a = sheet.row_values(rownum)
a.append(i.replace((filePath + '\\'), ''))
data.append(a)
workbook = xlsxwriter.Workbook(target_xlsx)
worksheet = workbook.add_worksheet()
font = workbook.add_format({"font_size":10})
for i in range(len(data)):
for j in range(len(data[i])):
worksheet.write(i, j, data[i][j], font)
workbook.close()
print("* * * * * *合并完成* * * * * *")
input()

上一篇:npoi操作excel 读取 插入 写入等


下一篇:移动端MescrollVue上下刷新