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
相关推荐
星空椰6 小时前
Python 面向对象高级:继承与类定义详解白露与泡影6 小时前
2026大厂Java面试题大全!牛客网最新版凯瑟琳.奥古斯特7 小时前
高阶子查询题目精炼风之所往_7 小时前
Python 3.4 新特性全面总结雪度娃娃7 小时前
转向现代C++——在意为改写的函数添加 override太阳上的雨天7 小时前
任何格式的文件转Markdownyaoxin5211238 小时前
419. 现代 Java IO 最佳实践 - 写入文本文件喵星人工作室8 小时前
C++火影忍者1.1.2weixin_468466858 小时前
纳米 AI 搜索新手极速上手指南凯瑟琳.奥古斯特8 小时前
数据库原理选择题精选