合并一个文文件夹下的所有Excel文件

 1 # Author:Winter Liu
 2 import xlrd
 3 import xlsxwriter
 4 import os
 5 
 6 # 获取文件目录
 7 file_list = os.listdir("C:\PycharmProjects\python level up\excel_file")
 8 end_xls = "xkb_end.xlsx"
 9 
10 data = []
11 for xls_name in file_list:
12     # 打开xls文件
13     f = xlrd.open_workbook("C:\PycharmProjects\python level up\excel_file\\" + xls_name)
14     # 创建表对象列表
15     sheets = f.sheets()
16     # 表对象
17     sheet = sheets[0]
18     # 表函数
19     n = sheet.nrows
20     m = 0 if len(data) == 0 else 1
21     for i in range(m, n):
22         # 获取每行
23         rdata = sheet.row_values(i)
24         data.append(rdata)
25 
26 # 备写文件打开
27 wr = xlsxwriter.Workbook(end_xls)
28 # 添加表
29 ws = wr.add_worksheet()
30 i = 0
31 for row in data:
32     for col_num, da in enumerate(row):
33         # 写入数据,逐个单元格
34         ws.write(i, col_num, da)
35     i = i+1
36 wr.close()

 

上一篇:STM32F1开发指南笔记18----OLED显示实验


下一篇:吃透OLED模块——玩转OLED模块各种使用方法