# coding=utf-8
# start
# 1、获取当前文件夹下所有excel文件名:excels
# 2、获取其中某个excel文件的所有sheet名:sheets
# 3、以第一个excel文件为基础创建一个新的excel:result.xlsx
# 4、for each_sheet in sheets:
# 4.1 for each_excel in excels[1,n]:
# 4.1.1 读取each_excel中名为each_excel的内容
# 4.1.2 以df格式获取数据
# 4.1.3 将数据以追加的模式写入到新的excel的each_sheet中
# end
import pandas
import pandas as pd
import xlrd
import os
import shutil
from openpyxl import load_workbook
# 存放要合并数据的文件夹路径
path = "C:/Users/**/export/data/"
# 要合并文件路径
def get_excels():
xlsx_names = [x for x in os.listdir(path) if x.endswith(".xlsx")]
return xlsx_names
# 获取某个excel的sheet
def get_sheets():
excels = get_excels()
first_excel = excels[0]
first_excel_path = path + first_excel
xl = pandas.ExcelFile(first_excel_path)
sheet_names = xl.sheet_names
# df = xl.parse(sheet_names)
return sheet_names
def meger_files():
# 1、获取当前文件夹下所有excel文件名:excels
使用python将多个excel文件的多个sheet各自合并
最新推荐文章于 2024-07-30 14:57:51 发布