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
相关推荐
KiefaC2 分钟前
【C++】红黑树的调整第二只羽毛2 分钟前
C++高性能内存池NullPointer83 分钟前
第21章:音频添加服务ULTRA??4 分钟前
动态内存管理:C语言malloc极简封装方案(修正版,可申请二维数组)梁正雄6 分钟前
9、Python面向对象编程-1say_fall7 分钟前
C++ 入门第一课:命名空间、IO 流、缺省参数与函数重载全解析霸王大陆13 分钟前
《零基础学 PHP:从入门到实战》模块十一:成为 PHP 侦探,精通错误处理与调试实战大全-1郝学胜-神的一滴15 分钟前
Python的内置类型:深入理解与使用指南松☆18 分钟前
C语言--结构体关于不上作者榜就原神启动那件事22 分钟前
【java后端开发问题合集】