使用的python包爲XlsxWriter
下載的連接
https://pypi.python.org/pypi/XlsxWriterpython
初級的例子:excel
def write_excel(info_list,colums,name,sheetname): import xlsxwriter workbook = xlsxwriter.Workbook(name) worksheet = workbook.add_worksheet(sheetname) info_length = len(info_list) col_len = len(colums) print info_length for row in range(0, info_length): row_value = info_list[row] if isinstance(row_value, dict): for col in range(0, col_len): value = info_list[row][colums[col]] worksheet.write(row, col, value) else: worksheet.write(row,0,row_value) workbook.close()
調用的方法:code
columns = ['port','cpname','dba','developer'] file_name = 'weibo_offline.xlsx' sheet_name = 'weibo_offline' write_excel(info_list, columns, file_name, sheet_name)