#coding:utf8
import xlwt #导入xlwt
def write_excel():
filePath = u"E:\\data.txt"
targetPath="E:\\data.xls"
f0 = xlwt.Workbook()
sheet1 = f0.add_sheet('Sheet1',cell_overwrite_ok=True)
result=""
index=0 #行索引
t_index = 0
titles = [u'本地视频码率',u'本地音频码率',u'远端视频码率',u'远端音频码率',u'本地帧率',u'本地宽度分辨率输出',u'本地高度分辨率输出']
params = ['_lv_nBytesSent','_la_nBytesSent','_rv_nBytesReceived','_ra_nBytesReceived','_lv_nFrameRateSent','_lv_nFrameWidthSent','_lv_nFrameHeightSent']
for t in titles: #写标题头
sheet1.write(0, t_index, t)
t_index = t_index + 1
with open(filePath) as f:
for line in f:
if '-------------------------------------' in line:
index = index + 1
continue
for p in range(len(params)):
if params[p] in line:
result = line.split("=")[1].replace("\n","").strip()
sheet1.write(index,p,float(result))
break
f0.save(targetPath)
if __name__ == '__main__':
write_excel()