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
相关推荐
桃西西呀2 小时前
刷短视频越刷越窄?SVD 奇异值分解,把 10 万条电影评分拆成你的品味特征大模型码小白2 小时前
Spring AI 框架中集成 MCP 的完整指南:从服务端到客户端的全流程实践青 春 记 忆2 小时前
零基础入门python29:用 pytest 验收完整 Flask 业务流程CarIise2 小时前
JavaScript进阶与轮播图实现 课堂笔记mayaairi3 小时前
JS DOM节点操作完全指南:增删改查与性能优化Demon--hx3 小时前
多态实现原理wanglei2007083 小时前
消息队列的协作模式三十岁老牛再出发3 小时前
8月25-26日总结小江的记录本3 小时前
【ORM 框架】MyBatis-Plus 核心特性、条件构造器、分页插件、乐观锁插件(附《思维导图》、《问题排查与实践清单》和《面试高频考点汇总》)jimy13 小时前
拷贝构造时,不用引用的话,按值传参会无限递归调用拷贝构造函数