问题描述
我是 Python 新手,我正在尝试将我的数据从 Python 写入 Excel 电子表格。这是我的python输出。 https://imgur.com/a/0eyRXvw 我希望 python 输出中的时间戳数据以这种格式写入 excel 电子表格 https://imgur.com/a/QpxVJse 但问题是我不知道如何从 python 输出中提取所有数据。对于启动时间戳,我只能提取一个数据值。如何从 python 输出中提取所有值并将其写入 Excel 电子表格?
这是我的代码:
import xlwt
pat1 = 'Boot 0x0100M'
pat2 = '2Sync:0 4'
pat3= '2Sync:1 C'
pat_no = 3
matchedline= ''
CE_count = 0
pattern_list = [pat1,pat2,pat3]
book = xlwt.Workbook(encoding = 'utf-8')
sheet1 = book.addsheet("Sheet1",cell_overwrite_ok=True)
sheet1.write(0,"spin)
sheet1.write(0,1,"start")
sheet1.write(0,2,"end")
count=0
for i in range(1,9,1):
sheet1.write(i,count)
count+=1
with open('C:\\Test_Automation\\spinup_spindown.txt') as file:
for line in file:
CE_count=1
for pattern in pattern_list:
if pattern in line:
matchedline=line
print(matchedline)
timestamp1=matchedline[0:13]
timestamp2=matchedline[0:13]
timestamp3=matchedline[0:13]
if pattern == pat1:
print(timestamp1)
sheet1.write(1,timestamp1)
if pattern == pat2:
print(timestamp2)
if pattern == pat3:
print(timestamp3)
book.save("C:\\Test_Automation\\trial.xls")
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)