python-excel 之带有格式及合并单元格样式的表格复制

from openpyxl import load_workbook


def copy_excel(totle_excel,totle_sheetname,down_excel,down_sheetname):
    down = load_workbook(down_excel)
    totle = load_workbook(totle_excel)
    totle_sheet = totle[totle_sheetname]
    down_sheet = down[down_sheetname]
    # 两个for循环遍历整个excel的单元格内容
    for i, row in enumerate(down_sheet.iter_rows()):
        for j, cell in enumerate(row):
            totle_sheet.cell(row=i + 1, column=j + 1, value=cell.value)
    totle.save(totle_excel)

代码说明:文件内容是从down_excel的down_sheetname复制到totle_excel的totle_sheetname

说明:以上代码可以将格式以及合并单元格的样式均复制到另一张表

注意:如果你是跨excel文件的复制且带有公式,不建议使用

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值