辞書データを表に書き込む
7256 ワード
#
import xlwt
#
def set_style(name,height,bold=False):
style = xlwt.XFStyle()
font = xlwt.Font()
font.name = name
font.bold = bold
font.color_index = 4
font.height = height
style.font = font
return style
# Excel
def write_excel(dict1):
f = xlwt.Workbook()
sheet1 = f.add_sheet('data',cell_overwrite_ok=True)
row0 = ["number","classname"]
colum0 = list(dict1.keys())
colum1 = list(dict1.values())
#
for i in range(0,len(row0)):
sheet1.write(0,i,row0[i],set_style('Times New Roman',220,True))
#
for i in range(0,len(colum0)):
sheet1.write(i+1,0,colum0[i],set_style('Times New Roman',220,True))
#
for i in range(0,len(colum1)):
sheet1.write(i+1,1,colum1[i],set_style('Times New Roman',220,True))
f.save('test2.xls')
if __name__ == '__main__':
write_excel(gt_dict)