import openpyxl def gen_excel(rows, headers, columns, file_name, title='sheet'): new = openpyxl.Workbook() sheet = new.active sheet.title = title for index, value in enumerate(headers): _ = sheet.cell(row=1, column=index+1, value=u'%s' % value) for row, target in enumerate(rows): for col, key in enumerate(columns): _ = sheet.cell(row=row+2, column=col + 1, value=u'%s' % target[key]) newworkbook = new.save(file_name) return newworkbook