def readfiletoexcel():
wb = xlwt.Workbook()
sheet = wb.add_sheet('端口信息')
#['Interface', 'PHY', 'Protocol', 'InUti', 'OutUti', 'inErrors', 'outErrors']
sheet.write(0,0,'Interface')
sheet.write(0,1,'PHY')
sheet.write(0,2,'Protocol')
sheet.write(0,3,'InUti')
sheet.write(0,4,'OutUti')
sheet.write(0,5,'inErrors')
sheet.write(0,6,'outErrors')
f = open("interface.txt", "r", encoding='utf-8')
lines = f.readlines()
result = "".join(lines)
res = result.split("\n")
j=0
for i in range(0,len(res)):
if len(re.findall(r'Interface',res[i]))>0:
j = i
regex = re.compile(r'GE.+\s+.+\s+.+\s+.+\s+.+\s+.+\s+.+',re.S)
if len(re.findall(regex, res[i])) > 0:
str = re.split('\s+',res[i])
print(str)
sheet.write(i-j,0,str[0])
sheet.write(i-j,1,str[1])
sheet.write(i-j,2,str[2])
sheet.write(i-j,3,str[3])
sheet.write(i-j,4,str[4])
sheet.write(i-j,5,str[5])
sheet.write(i-j,6,str[6])
wb.save("result.xls")
readfiletoexcel()
python往excel中写端口信息
Guaiacum_2024-10-12 23:13
相关推荐
郑州光合科技余经理4 小时前
代驾系统架构拆解:订单链路、权限组织与私有化源码交付天才测试猿7 小时前
2026软件测试面试八股文(含答案+文档)码哥DFS7 小时前
二叉树的直径paopaokaka_luck8 小时前
基于springboot3+vue3的企业考勤管理系统(部门树递归、Echarts图形化分析)张小凡vip8 小时前
python--爬虫--成熟的爬虫框架ScrapyPluchon8 小时前
Java个人综合项目——萌部落社区V2.0梦雨生生9 小时前
java开发工具(学习第一天)不瘦80斤不改名9 小时前
01-vibe-coding-起源与本质夜雪一千9 小时前
如何对新闻数据进行模糊去重啊啊啊啊啊!!!!10 小时前
【c++】stack和queue的接口使用以及底层实现