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
相关推荐
用户8356290780517 小时前
Python 删除 Excel 工作表中的空白行列Json_7 小时前
使用python-fastApi框架开发一个学校宿舍管理系统-前后端分离项目数据智能老司机14 小时前
精通 Python 设计模式——分布式系统模式数据智能老司机15 小时前
精通 Python 设计模式——并发与异步模式数据智能老司机15 小时前
精通 Python 设计模式——测试模式数据智能老司机15 小时前
精通 Python 设计模式——性能模式c8i15 小时前
drf初步梳理每日AI新事件15 小时前
python的异步函数这里有鱼汤16 小时前
miniQMT下载历史行情数据太慢怎么办?一招提速10倍!databook1 天前
Manim实现脉冲闪烁特效