1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| import xlwt
titlestyle=xlwt.XFStyle()
titlefont=xlwt.Font() titlefont.name="宋体" titlefont.bold=True titlefont.height=11*20 titlefont.colour_index=0x08 titlestyle.font=titlefont
cellalign=xlwt.Alignment() cellalign.horz=0x02 cellalign.vert=0x01 titlestyle.alignment=cellalign
borders=xlwt.Borders () borders.right=xlwt.Borders.DASHED borders.bottom=xlwt.Borders.DOTTED titlestyle.borders=borders
datestyle = xlwt.XFStyle()
bgcolor = xlwt.Pattern() bgcolor.pattern=xlwt.Pattern.SOLID_PATTERN bgcolor.pattern_fore_colour=22 datestyle.pattern=bgcolor
wb=xlwt.Workbook()
ws = wb.add_sheet("CNY")
ws.write_merge(0, 1, 0, 5,"2019年货币兑换表",titlestyle)
data = (("Date", "英镑","人民币","港币","日元","美元" ),("01/01/2019", 8.722551, 1, 0.877885, 0.062722, 6.8759 ),("02/01/2019", 8.634922, 1, 0.875731, 0.062773, 6.8601 )) for i, item in enumerate(data): for j, val in enumerate(item): if j == 0 : ws.write(i+2,j,val,datestyle) else: ws.write(i+2, j, val)
wb.save("2019CNY.xls")
|