zoukankan      html  css  js  c++  java
  • python 写入execl记录

    记录代码中关于写execl的操作

    # 创建execl
    workbook = xlwt.Workbook(encoding='utf8')
    # 创建样式实例
    style = xlwt.XFStyle()
    # 创建位置样式
    alignment = xlwt.Alignment()
    # 设置居中
    alignment.vert = xlwt.Alignment.VERT_CENTER
    # 将位置样式绑定到样式实例
    style.alignment = alignment
    
    for instance_id, items in result.items():
        # 新建sheet表
        sheet = workbook.add_sheet(instance_id)
        # 设置列宽度
        sheet.col(0).width = 15000
        sheet.col(1).width = 10000
        # 写入单元格
        sheet.write(0, 0, label='Theme')
        sheet.write(0, 1, label='AppId/Address')
        row_index = 1
        for theme, clients in items.items():
            # count = len(clients)
            # 写入合并单元格 [row_start, row_end, col_start, col_end, content, style]
            # sheet.write_merge(row_index, row_index + count - 1, 0, 0, theme, style)
            for client in clients:
                # 写入单元格  [row, col, content]
                sheet.write(row_index, 0, theme)
                sheet.write(row_index, 1, client)
                row_index += 1
    # 保存到文件
    workbook.save('file.xls')
    
  • 相关阅读:
    pip 配置国内源
    python + excel工资条自动生成
    Mysql 查看表结构
    win10中Pycharm连接mysql时区错误的解决
    kali linux中mariadb加上密码
    静态链表的基本操作
    静态链表dd
    静态链表
    单链表的基本操作
    单链表
  • 原文地址:https://www.cnblogs.com/Peter2014/p/10558639.html
Copyright © 2011-2022 走看看