import re
import xlwt
f=open("info.txt","r",encoding="utf-8")
file=f.read()
f.close()
# 把要提取的多个参数名写在列表内
fields=["deliveryRowId","materialNo"]
workbook = xlwt.Workbook(encoding = 'utf-8')
worksheet = workbook.add_sheet('Worksheet_yyn')
for field in fields:
# 查找数据的正则表达式
search_key='"'+field+'":"(.*?)"'
result_data=re.findall(search_key,file)
i=1
j=fields.index(field)
worksheet.write(0,j, label=field)
for data_id in result_data:
worksheet.write(i,j, label=data_id)
i=i+1
workbook.save('test_info.xls')