python简单生成excel

# !/usr/bin/env python3
# -*- coding: utf-8 -*-
import xlwt

def generate_excel(file_name, data):
work_book = xlwt.Workbook(encoding='utf-8')
sheet = work_book.add_sheet('sheet_name')
    sheet.write(0, 0, 'title_name')
sheet.write(0, 1, '
title_name')
    row_count = 0
for
title_value1, title_value2 in data.items():
        row_count += 1
sheet.write(row_count, 0, f'{
title_value1}')
        sheet.write(row_count, 1, f'{title_value2 }')
    work_book.save(f'{file_name}.xls')
posted @ 2021-08-12 12:07  wyz_1  阅读(364)  评论(0编辑  收藏  举报