python-自动化篇-办公-excel-实例应用(一维转二维)

文章目录

准备

放根目录

代码

python 复制代码
import openpyxl
wb=openpyxl.load_workbook('业绩表.xlsx')
if not '二维表' in wb.sheetnames:
    nws=wb.create_sheet('二维表')
    ws=wb.worksheets[0]
    rngs=list(ws.values)[1:]
    mm=list({m.value:'' for m in ws['b'][1:]})
    name=list({m.value:'' for m in ws['a'][1:]})
    nws.append(['姓名']+mm)
    for n in name:
        l=[(n,m) for m in mm]
        nws.append([n]+[list(filter(lambda r:t[0]==r[0] and t[1]==r[1],rngs))[0][2] for t in l])
    wb.save('业绩表.xlsx')

效果

相关推荐
学习指针路上的小学渣6 分钟前
Selenium笔记
python·selenium
SunnyDays101111 分钟前
使用 Python 在 Excel 中应用数据验证:详细指南
python·excel·数据验证
Jelena1577958579215 分钟前
1688.item_get_app接口:包装尺寸重量信息深度解析
开发语言·前端·python
用户83562907805122 分钟前
使用 Python 精准控制 Word 段落格式
后端·python
NULIWEIMENXIANG23 分钟前
ArcPy 程序调用 QGIS 进程实现几何拓扑检查
python·arcgis·gis
rookie软工26 分钟前
Qt代理委托实现
开发语言·python·qt
love530love30 分钟前
Windows 本地部署 IDM-VTON 虚拟试衣:排障版教程
人工智能·windows·python·virtual try-on
忘忧记32 分钟前
pytest进阶参数化用法
前端·python·pytest
JavaWeb学起来39 分钟前
Python学习教程(二)字符串
开发语言·python·python基础
归寻太乙43 分钟前
2026年03月27日—Python基础—Python背景知识与环境搭建
开发语言·python