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
相关推荐
小巧的砖头1 分钟前
C#会重蹈覆辙吗?系列之2:反射及元数据的性能问题凯瑟琳.奥古斯特4 分钟前
力扣1009补码解法C++实现2601_963645928 分钟前
【2026最新】MATLAB教程(附安装包,非常详细)闲猫1 小时前
Python 虚拟环境 virtualenv & uvicorn 服务搭建 & FAstAPI 使用AI视觉网奇1 小时前
vllm 多卡部署精明的身影1 小时前
网络计划WebApp求解:融合Python与AI决策的项目管理系统AI科技星2 小时前
全域谱分析:无穷维超复数信息场分形统一场论——自然、量子、金融多重分形第一性原理完整体系(中英双语终稿)三月不知肉味y2 小时前
2026-07-05-JAVA面试场景题训练用户0332126663672 小时前
使用 Python 在 Word 文档中添加批注蜡笔削薪2 小时前
财联万业(杭州)数字科技有限公司能否给代理划定独家经营区域?