python2.7小程序练手源码 读取txt文件生成excel

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012811841/article/details/86165084
#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()

 

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试