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
相关推荐
小oo呆13 分钟前
【学习心得】Jupyter 如何在conda的base环境中其他虚拟环境内核愚润求学14 分钟前
【Linux】动静态库链接原理呦呦彬22 分钟前
【问题排查】easyexcel日志打印Empty row!Tummer836332 分钟前
C#+WPF+prism+materialdesign创建工具主界面框架九章云极AladdinEdu39 分钟前
GPU与NPU异构计算任务划分算法研究:基于强化学习的Transformer负载均衡实践好吃的肘子1 小时前
MongoDB 应用实战ghost1431 小时前
C#学习第23天:面向对象设计模式小白学大数据1 小时前
Scrapy框架下地图爬虫的进度监控与优化策略浊酒南街1 小时前
TensorFlow之微分求导立秋67891 小时前
用Python绘制梦幻星空