码迷,mamicode.com
首页 > 编程语言 > 详细

python xlrd xlwt获取数据到execl表格样例

时间:2018-08-29 18:03:19      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:min   art   结束   retcode   idt   ons   work   xlwt   ble   

import mock

#coding:gbk
from xlrd import open_workbook
import mock
import xlrd
import xlwt
from xlutils.copy import copy
import os
acct = mock.acct_id
data = mock.acct_data
start_time = mock.start_time
print start_time
end_time = mock.end_time5
haoshi = mock.result_end
req_sn = mock.mock(acct).format(acct, data)[‘request_sn‘]
ww = ["acct",‘wwwwww‘]
print
if os.path.exists(‘C:\Users\Administrator\desktop\excel.xls‘):
pass
else:
book = xlwt.Workbook(encoding=‘gbk‘,style_compression=0)
sheet = book.add_sheet(‘数据统计‘,cell_overwrite_ok=True)
book.save(‘C:\Users\Administrator\desktop\excel.xls‘)
book = open_workbook(‘C:\Users\Administrator\desktop\excel.xls‘,‘w+b‘)
rows = book.sheets()[0].nrows
excel = copy(book)
table = excel.get_sheet(0)
row = rows
for i in range(7):
table.col(i).width=256*35
row0 = [u‘response_sn‘,u‘retcode‘,u‘acct_id‘,u‘请求时间‘,u‘结束时间‘,u‘耗时‘]
row1 = [req_sn, mock.retcode, acct, start_time, end_time, haoshi]
if row == 0:
for i in range(len(row0)):
table.write(row, i, row0[i])
table.write(row + 1 , i, row1[i])
else:
for i in range(0,len(row0)):
table.write(row,i,row1[i])
excel.save(‘C:\Users\Administrator\desktop\excel.xls‘)

python xlrd xlwt获取数据到execl表格样例

标签:min   art   结束   retcode   idt   ons   work   xlwt   ble   

原文地址:http://blog.51cto.com/13945009/2166080

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!