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
相关推荐
勇闯逆流河34 分钟前
【C++】C++11(下)云栈开源日记38 分钟前
Python 开发技术栈梳理:从数据库、爬虫到 Django 与机器学习青衫码上行38 分钟前
【Java Web学习 | 第15篇】jQuery(万字长文警告)胡萝卜3.06 小时前
掌握C++ map:高效键值对操作指南电子_咸鱼7 小时前
【STL string 全解析:接口详解、测试实战与模拟实现】哈茶真的c7 小时前
【书籍心得】左耳听风:传奇程序员练级攻略沐知全栈开发7 小时前
ionic 选项卡栏操作详解曹牧7 小时前
C#中,#region和#endregion顾安r7 小时前
11.22 脚本打包APP 排错指南蒙小萌19938 小时前
Swift UIKit MVVM + RxSwift Development Rules