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
相关推荐
Dxy12393102168 小时前
Python项目打包成EXE完整教程(PyInstaller实战避坑)bamb008 小时前
一个项目带你入门AI应用开发010566469 小时前
Python康复训练——常用标准库骊城英雄9 小时前
基于C#+avalonia ui实现的跨平台点胶机灌胶监控控制上位机软件吾儿良辰9 小时前
一个被BCL遗忘的高性能集合:C# CircularBuffer<T>深度解析昆曲之源_娄江河畔9 小时前
Python如何安装flask, pymssqlLeighteen9 小时前
`try-finally` 里的 `return`:为什么 `finally` 会悄悄改掉返回值、吞掉异常0566469 小时前
Python康复训练——控制流与函数峥无9 小时前
C++11 深度详解:现代 C++ 基石全梳理阿米亚波10 小时前
【C++ STL】std::unordered_multimap