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 小时前
安装Bash completion解决tab不能补全问题失败尽常态5232 小时前
用Python实现Excel数据同步到飞书文档2501_904447742 小时前
OPPO发布新型折叠屏手机 起售价8999青龙小码农2 小时前
yum报错:bash: /usr/bin/yum: /usr/bin/python: 坏的解释器:没有那个文件或目录大数据追光猿2 小时前
Python应用算法之贪心算法理解和实践Leuanghing3 小时前
【Leetcode】11. 盛最多水的容器彳卸风3 小时前
Unable to parse timestamp value: “20250220135445“, expected format isdorabighead3 小时前
JavaScript 高级程序设计 读书笔记(第三章)xinxiyinhe4 小时前
如何设置Cursor中.cursorrules文件