import xlrd
# xlrd 1.2.0版本才可以
import xlsxwriter
import os
dir_path=os.path.abspath('.')
file_path=os.path.join(dir_path,'data','202112combineg')
file_path1=os.path.join(dir_path,'data','202112combineg','combin')
print(file_path)
import pandas as pd
# 创建一个工作簿并添加一个工作表
# workbook=xlsxwriter.Workbook(file_path+"/demo1.xlsx")
# worksheet=workbook.add_worksheet()
# workbook.close()
source_xls=[]
for root ,dirs,filename in os.walk(file_path1):
for file in filename:
source_xls.append(file_path1+"/"+file)
#soruce_xls=[file_path+"/2021.12.01-2021.12.01 11669_AI课情分析报告.xlsx",file_path+"/2021.12.02-2021.12.02 11669_AI课情分析报告.xlsx"]
target_xls=file_path+"/demo1.xlsx"
data=[]
for i in source_xls:
# wb=xlrd.open_workbook(i)
wb=xlrd.open_workbook(i)
for sheet in wb.sheets():
for rownum in range(sheet.nrows):
data.append(sheet.row_values(rownum))
# print(data)
#写入数据
workbook=xlsxwriter.Workbook(target_xls)
worksheet=workbook.add_worksheet()
font=workbook.add_format({"font_size":14})
# for i in range(len(data)):
# for j in range(len(data[i])):
# worksheet.write(i,j,data[i][j],font)
for i in range(len(data)):
for j in range(len(data[i])):
for j in range(10):
worksheet.write(i,j,data[i][j],font)
workbook.close()
print('合并完成')
|