python操作Excel
def write_excel():
f = xlwt.Workbook()
sheet1 = f.add_sheet(u'sheet1', cell_overwrite_ok=True)
row0 = [u'业务', u'状态', u'北京', u'上海', u'广州', u'深圳', u'状态小计', u'合计']
column0 = [u'机票', u'船票', u'火车票', u'汽车票', u'其他']
status = [u'预订', u'出票', u'退票', u'业务小计']
for i in range(0, len(row0)):
sheet1.write(0, i, row0[i], set_style('Times New Roman', 220, True))
i, j = 1, 0
while i < 4 * len(column0) and j < len(column0):
sheet1.write_merge(i, i + 3, 0, 0, column0[j], set_style('Times New Roman', 220, True))
sheet1.write_merge(i, i + 3, 7, 7)
i += 4
j += 1
sheet1.write_merge(21, 21, 0, 1, u'合计', set_style('Times New Roman', 220, True))
i = 0
while i < 4 * len(column0):
for j in range(0, len(status)):
sheet1.write(j + i + 1, status[j])
i += 4
f.save('demo.xlsx')
if __name__ == '__main__':
write_excel()