import os
import pandas as pd# 功能:遍历目录下的所有xls文件,合并到指定的一个文件def main():#指定目录base = 'C:\\Users\\11578\\Desktop\\05'desktop =  os.path.join(os.path.expanduser("~"), 'Desktop')#存放所有xls表的数据allLineData = pd.DataFrame()for excelFile in findAllFile(base):# 读取工作簿和工作簿中的工作表oneFileData =pd.read_excel(excelFile)# append忽略行头(忽略第一行)allLineData=allLineData.append(oneFileData, ignore_index=True)# print(allLineData)#写到桌面writer=pd.ExcelWriter(os.path.join(desktop,'合并后的文件.xls'))# 使用to_excel将之前读取的工作簿中工作表的数据写入到新建的工作簿的工作表中allLineData.to_excel(writer, index=False)# 保存并且关闭工作簿writer.save()#查找base目录下的所有xls和xlsx文件
def findAllFile(base):for root, ds, fs in os.walk(base):for f in fs:if f.endswith('.xls') or f.endswith('.xlsx'):fullname = os.path.join(root, f)yield fullnameif __name__ == '__main__':main()

gui版本

from tkinter import *
import os
import pandas as pddef gui():# 第1步,实例化object,建立窗口windowwindow=Tk()# 第2步,给窗口的可视化起名字window.title('Aggregation Excel')window.geometry('530x150')  # 这里的乘是小x# 桌面desktop=os.path.join(os.path.expanduser("~"), 'Desktop')strvar=StringVar()strvar.set(desktop)l1=Label(window, text="扫描excel的目录")e1=Entry(window, show=None, width=50)l2=Label(window, text="合并后文件的存放路径")e2=Entry(window, show=None, width=50, textvariable=strvar)def insert_point():  # 在鼠标焦点处插入输入内容# 扫描excel的目录路径e1value=e1.get()# 合并后存放的目录路径e2value=e2.get()# t.insert('insert', var)aggExcel(e1value,e2value)# 第6步,创建并放置两个按钮分别触发两种情况btn1=Button(window, text='开始合并', width=10,height=2, command=insert_point)t=Text(window, height=3)l1.grid(row=1, column=1, sticky=E)e1.grid(row=1, column=2, sticky=E)l2.grid(row=2, column=1, sticky=E)e2.grid(row=2, column=2, sticky=E)btn1.grid(row=4, column=1, sticky=E)# 第8步,主窗口循环显示window.mainloop()def aggExcel(filedir,writePlace):# 指定目录# base='C:\\Users\\11578\\Desktop\\05'# base = e1value# 存放所有xls表的数据allLineData=pd.DataFrame()for excelFile in findAllFile(filedir):# 读取工作簿和工作簿中的工作表oneFileData=pd.read_excel(excelFile)# append忽略行头(忽略第一行)allLineData=allLineData.append(oneFileData, ignore_index=True)# print(allLineData)# 写到桌面writer=pd.ExcelWriter(os.path.join(writePlace, '合并后的文件.xls'))# 使用to_excel将之前读取的工作簿中工作表的数据写入到新建的工作簿的工作表中allLineData.to_excel(writer, index=False)# 保存并且关闭工作簿writer.save()#查找base目录下的所有xls和xlsx文件
def findAllFile(base):for root, ds, fs in os.walk(base):for f in fs:if f.endswith('.xls') or f.endswith('.xlsx'):fullname = os.path.join(root, f)yield fullnameif __name__ == '__main__':gui()

打包成exe:
打开文件所在的目录下:cmd执行命令

pyinstaller -w xxx.py

GUI参考:https://www.cnblogs.com/shwee/p/9427975.html
pandas参考:https://zhuanlan.zhihu.com/p/31541902
打包教程:https://blog.51cto.com/u_15284226/2988724

python 读取多个excel整合成一个新的excel(有gui版本)相关推荐

  1. 使用Python读取LabVIEW TDMS 格式文件转成 pandas及Excel

    个人用Django开发的博客已上线,欢迎访问:https://www.zhibibin.com Labview的TMDS格式文件在很多偏硬件相关的工作中经常出现,有时候面临将TDMS转成Excel通用 ...

  2. 新手个人笔记-java获取Excel模板并生成新的Excel导出

    前端大概的样式: 模板: 效果: HTML: <span class="l" style="margin-left: 10px;"><a cl ...

  3. python提取txt数据到excel_python 读取txt中每行数据,并且保存到excel中的实例

    使用xlwt读取txt文件内容,并且写入到excel中,代码如下,已经加了注释. 代码简单,具体代码如下: # coding=utf-8 ''' main function:主要实现把txt中的每行数 ...

  4. python逐行读取txt写入excel_python 读取txt中每行数据,并且保存到excel中的实例

    使用xlwt读取txt文件内容,并且写入到excel中,代码如下,已经加了注释. 代码简单,具体代码如下: # coding=utf-8 ''' main function:主要实现把txt中的每行数 ...

  5. PHP 与Python 读取大文件的区别

    php读取大文件的方法 <?php function readFile($file) {# 打开文件$handle = fopen($file, 'rb');while (feof($handl ...

  6. java 实现 excel sheet 拷贝到另一个Excel文件中 poi

    public class CopyExcelSheetToAnotherExcelSheet { public static void main(String[] args) throws FileN ...

  7. python读取excel多个sheet页并合并成一页

    python读取excel多个sheet页并合并成一页 import xlrd import xlwtdata = xlrd.open_workbook("database.xlsx&quo ...

  8. python读取excel,数字都是浮点型,日期格式是数字的解决办法

    excel文件内容: 读取excel: # coding=utf-8 import xlrd import sysreload(sys) sys.setdefaultencoding('utf-8') ...

  9. python 读取excel中单元格的内容

    python 读取excel中单元格的内容 excel文件内容: 读取excel代码: # coding=utf-8 import xlrd import sysreload(sys) sys.set ...

最新文章

  1. 第十八章 MySQL Workbench5.2使用(待续)
  2. golang map嵌套struct 结构体字段 不能直接修改 解决方法
  3. 反射中Class.forName()和ClassLoader.loadClass()的区别
  4. python3 和python2文件相互转换
  5. c++上传oss中文路径报错_C# 从Oss对象存储器上下载文件到本地打包下载代码
  6. 理论基础 —— 排序 —— 堆排序
  7. 多进程使用wikimedia数据训练word2vec模型
  8. matlab gui教程 计算器,matlab gui编写的计算器程序
  9. 从五个维度来谈谈视觉设计师如何阐述设计风格
  10. python中小学生编程学习-推荐几个适合小白学习Python的免费网站
  11. VMware虚拟机无法识别U盘解决方案
  12. 计算机毕设题目设计与实现(论文+源码)_kaic
  13. golang数据结构初探之字典map
  14. 怎样理解心藏神,肝藏魂,脾藏意,肺藏魄,肾藏精志?
  15. 二元关系——离散数学part 1
  16. 腊八节的传说计算机导论,老潍县地区春节习俗(3页)-原创力文档
  17. 数据库--------视图
  18. ipv4中的子网掩码
  19. 什么是回调?回调函数又是什么?
  20. 用可编程逻辑器件FPGA LCMXO2-4000HC-6MG132I 实现智能汽车解决方案设计

热门文章

  1. 淘宝又现坑爹极品山寨
  2. #千锋逆战班 Java JDK8
  3. millenium panel汉化版安装教程
  4. ZZ最近做了温水煮青蛙的试验 感觉真的上当了
  5. git branch 分支命令图文详解
  6. DDL, DML, DCL, 和TCL的含义
  7. 安装SSL证书后,解决混合内容造成页面错误提示的处理办法
  8. MySQL的备份策略
  9. 作品集的整理思路-设计资源
  10. 何星火致全体镇邦会战友的一封信