合并n个excel工作表到一个工作表

 import xlrd
 import xlsxwriter
 
 source_xls = ["D:/python/1.xlsx", "D:/python/2.xlsx"]
 target_xls = "D:/python/3.xlsx"
 
 # 读取数据
 data = []
 for i in source_xls:
     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)
 # 关闭文件流
 workbook.close()

python 合并工作表

你可能感兴趣的:(python)