首页 > 代码库 > python之excel表格操作

python之excel表格操作

# coding: utf-8

#==================================================================================
# Author: changbo - EMail:changbo@hmg100.com #Last modified:2017-4-8 #filename:run_status.py #Description:create file 952700000ACH5Q05运行情况, Base xlswriter
# blog:http://www.cnblogs.com/changbo #================================================================================== import xlsxwriter import time nowtime = time.strftime(‘%Y-%m-%d ‘, time.localtime(time.time())) nowtime1 = (time.strftime(‘_%Y_%m_%d ‘, time.localtime(time.time()))).strip() file_name = u‘952700000ACH5Q05运行情况%s.xlsx‘ % nowtime1 title = [u‘PIR报警次数‘, u‘广域网唤醒次数‘, u‘局域网唤醒次数‘, u‘Codec总持续运行时间‘, u‘Codec持续运行时间(彩色)‘, u‘Codec持续运行时间(黑白)‘, u‘Codec持续运行时间(报警)‘, u‘Codec持续运行时间(预览)‘, u‘软重启次数‘, u‘硬重启次数‘, u‘‘] title1 = [u‘当天‘, u‘最近一个月‘] def titlename(): # create file workbook = xlsxwriter.Workbook(file_name) merge_format = workbook.add_format({ ‘bold‘: True, ‘align‘: ‘center‘, ‘valign‘: ‘vcenter‘, }) # create sheet worksheet = workbook.add_worksheet() worksheet.set_column(0, 29, 15) worksheet.merge_range(0, 0, 1, 0, u‘日期‘, merge_format) worksheet.merge_range(0, 1, 1, 1, u‘当前版本(最新?)‘, merge_format) worksheet.write(‘A3‘, nowtime) x = -1 for i in range(67, 87, 2): toptitle = ‘%s1:%s1‘ % (chr(i), chr(i + 1)) secondtitle = ‘%s2‘ % chr(i) secondtitle2 = ‘%s2‘ % chr(i + 1) x += 1 worksheet.merge_range(toptitle, title[x], merge_format) worksheet.write(secondtitle, title1[0], merge_format) worksheet.write(secondtitle2, title1[1], merge_format) worksheet.merge_range(‘W1:W2‘, u‘当天AP掉线次数‘, merge_format) worksheet.merge_range(‘X1:AA1‘, u‘电源信息‘, merge_format) worksheet.write(‘X2‘, u‘安装情况‘, merge_format) worksheet.write(‘Y2‘, u‘电池类型‘, merge_format) worksheet.write(‘Z2‘, u‘供电情况‘, merge_format) worksheet.write(‘AA2‘, u‘剩余电量‘, merge_format) worksheet.merge_range(‘AB1:AB2‘, u‘Codec死机次数‘, merge_format) workbook.close() return if __name__ == ‘__main__‘: titlename()

 END!

python之excel表格操作