python使用xlwt写入excel

def write_list_to_xls(file_name, sheet_name, message_list, firstcolumn_list, param_list):
    # file_name 文件名
    # sheet_name 表单名
    # message_list要写入excel文件的参数list
    # firstcolumn_list第一行参数中的值
    # param_list,message_list中每个元素的key值
    workbook = xlwt.Workbook()
    sheet = workbook.add_sheet(sheet_name, cell_overwrite_ok=True)
    # 往第一行中写数据
    first_column_count = 0
    for prompt in firstcolumn_list:
        sheet.write(0, first_column_count, prompt.decode('UTF-8'))
        first_column_count += 1
    # 开始写后面的数据
    row_count = 1
    for message in message_list:
        # 第几列
        temp_column_count = 0
        for key in param_list:
            sheet.write(row_count, temp_column_count, message.get(key))
            temp_column_count += 1
        # 行号递增
        row_count += 1
    workbook.save(file_name)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值