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
相关推荐
景彡先生4 小时前
Python Selenium详解:从入门到实战,Web自动化的“瑞士军刀”程序员卷卷狗4 小时前
JVM 调优实战:从线上问题复盘到精细化内存治理lly2024065 小时前
ASP Folder:深入解析其功能与使用技巧雪域迷影5 小时前
Go语言中通过get请求获取api.open-meteo.com网站的天气数据珺毅同学6 小时前
YOLO输出COCO指标及YOLOv12报错ysdysyn7 小时前
C# 进程管理实战:检查与启动EXE程序的完整指南IDOlaoluo7 小时前
PHP-5.2.1.tar.gz 离线安装教程:从源码编译到配置的详细步骤(附安装包)2401_841495648 小时前
Windows 系统中ffmpeg安装问题的彻底解决wangjialelele8 小时前
Qt中的常用组件:QWidget篇waysolong908 小时前
MCP服务构建、使用