首页
电子手办柜
友链
统计
更多
留言
Search
1
《绿皮书》《Green Book》
579 阅读
2
如何用Siri唤醒电脑(by服务器)
425 阅读
3
欢迎使用 Typecho
327 阅读
4
斯人若彩虹,遇上方知有。
274 阅读
5
Remove-Password-on-Excel-VBA-Project(简单绕过VBA项目密码)
265 阅读
默认分类
杂谈
灵魂
代码
登录
Search
标签搜索
python
小冷柠's Blog
累计撰写
78
篇文章
累计收到
5,637
条评论
首页
栏目
默认分类
杂谈
灵魂
代码
页面
电子手办柜
友链
统计
留言
搜索到
1
篇与
的结果
2024-03-11
多个表格在不同下文件夹下面汇总到同一个表不同工作簿的方法
文件夹结构--A -1 -2 -3 --B -1 -2 -3 表格结构 --A , --B 将文件夹里面的123 都汇总到字母AB 中去import os import xlwings as xw import pandas as pd path = f"{os.path.split(os.path.realpath(__file__))[0]}/" wb1 = xw.books("JD优惠券百补各店铺承担比例信息截止2024年1月.xlsx") shop_list = [x for x in wb1.sheet_names][3:] def readsheet_to_sheet(sheetname): folder_path = path + sheetname all_df = pd.DataFrame() for filename in os.listdir(folder_path): if filename.endswith('.xlsx'): file_path = os.path.join(folder_path, filename) print(f"Reading sheets from {file_path}:") with xw.Book(file_path) as wb: for sheet in wb.sheets: # 读取工作表数据并跳过第一行 df = sheet.used_range.options(pd.DataFrame, index=False, header=1).value # 打印工作表名称和数据 print(f"\nSheet: {sheet.name}") print(df) all_df = pd.concat([all_df,df],ignore_index=True) wb1.sheets[sheetname].range("A2").options(header = False , index = False).value = all_df if __name__ == "__main__": for i in shop_list: readsheet_to_sheet(sheetname=i)
2024年03月11日
19 阅读
0 评论
0 点赞