首页 > 编程语言 > 详细

python操作Excel

时间:2019-02-20 17:37:33      阅读:163      评论:0      收藏:0      [点我收藏+]
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()

 

python操作Excel

原文:https://www.cnblogs.com/yellowhat/p/10407891.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!