一段从TXT导入excel的py脚本

时间:2021-10-27 20:25:07

#创建文件
file = Workbook(encoding='utf-8')
#创建sleet
tableTotalTime = file.add_sheet('TotalTime')
#每列给出名称
tableTotalTime.write(0,0,'TotalTime')

 

TotalTimefpath = r'C:\Users\XXXX\Desktop\packet\autoScript\TotalTime.log'
#打开文件并读取
f = open(TotalTimefpath,'r')
line = f.readlines()
len = 1
for item in line:
#转为list
list = item.split( )
TotalTime = list[1]
print u"TotalTime耗时为:"+TotalTime+"ms"
# print Cpu 并存入excel为整数类型
tableTotalTime.write(len,0,int(TotalTime))
len = len + 1
f.close()
#保存excel并命名
file.save('TotalTime.xlsx')