import os
from openpyxl import Workbook, load_workbook
import re
import shutil
def copy_data():
wb = Workbook()
sh = wb.active
all_data = []
for name in os.listdir(r'./办公自动化/files'):
# print(name)
if re.findall('xlsx', name):
# print(name)
path = f'./办公自动化/files/{name}'
# print(path)
tmp_wb = load_workbook(path)
tmp_sh = tmp_wb.active
for r in range(1, tmp_sh.max_row + 1):
row_value = []
for c in range(1, tmp_sh.max_column + 1):
value = tmp_sh.cell(r, c).value
row_value.append(value)
# print(row_value)
if row_value not in all_data:
all_data.append(row_value)
# print(all_data)
for data in all_data:
sh.append(data)
wb.save('./办公自动化/files/汇总.xlsx')
shutil.move('./办公自动化/files/汇总.xlsx','./办公自动化/files/数据合并.xlsx')
if __name__ == '__main__':
copy_data()